2009-10-13 3 views
0

je le modèle suivant:xslt1.0 problème variables

<xsl:template name="theday"> 
    <xsl:param name="thisday" /> 

    <xsl:variable name='holiday' select='foo'/><!-- made this static for testing --> 

    <td class="{$holiday}"> <!-- no value is inserted in class --> 

     <a> 
      <xsl:attribute name='href'><xsl:value-of 
       select="concat('?date=',$thisday)" /></xsl:attribute> 
      <xsl:value-of select="date:day-in-month($thisday)" /> 
     </a> 
    </td> 
</xsl:template> 

Je compte obtenir HTML quelque chose comme ceci:

<td class="foo"> 
    <a href="?date=2009-11-02">2</a> 
</td> 

Malheureusement, je reçois:

<td class=""> 
    <a href="?date=2009-11-02">2</a> 
</td> 

Qu'est-ce que Ai-je disparu?

Répondre

3

Essayez ceci:

<xsl:variable name='holiday'>foo</xsl:variable> 

ou

<xsl:variable name='holiday' select="'foo'"/> 

Comment ça marche: l'attribut select attend une expression à évaluer; Puisque vous n'avez probablement pas d'élément foo au contexte, il est résolu en tant que chaîne vide.

1

Le problème est que <xsl:variable name='holiday' select='foo'/> sélectionne la nodelist 'foo' (qui est vide) pas la chaîne foo. Si vous aviez xml

<a> 
    <foo>B</foo> 
</a> 

alors (quand actuellement à a) <xsl:variable name='holiday' select='foo'/> donnerait 'B'.

Pour résoudre ce problème spécifier une constante:

<xsl:variable name='holiday' select="'foo'"/>