xslt1.0 variable problem

I have the following template:

<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>

I expect to get HTML something like this:

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

Unfortunately, I get:

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

What am I missing?

13.10.2009 20:25:31
2 ОТВЕТА
РЕШЕНИЕ

Try this:

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

or

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

How it works: the select attribute expects an expression to be evaluated; since you probably don't have a foo element at context, it is resolved as an empty string.

3
13.10.2009 20:44:12

The problem is that <xsl:variable name='holiday' select='foo'/> selects the nodelist 'foo' (which is empty) not the string foo. If you had xml

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

then (when currently at a) <xsl:variable name='holiday' select='foo'/> would give 'B'.

To fix this specify a constant:

<xsl:variable name='holiday' select="'foo'"/>
1
13.10.2009 20:46:22