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

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

I expect to get HTML something like this:

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

Unfortunately, I get:

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

What am I missing?

13.10.2009 20:25:31

Try this:

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


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

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


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'"/>
13.10.2009 20:46:22