tags:

views:

33

answers:

2

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?

+3  A: 

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.

Rubens Farias
+1  A: 

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'"/>
Kathy Van Stone