I have for quite a few years used this primitive way of
translating from a month number to a month name.
<xslt:variable name="$months">
<m>January</m><m>February</m><m>March</m><m>April</m>
<m>May</m><m>June</m><m>July</m><m>August</m>
<m>September</m><m>October</m><m>November</m><m>December</m>
</xsl:variable>
The actual lookup was done using a this expression
<xsl:value-of
select="$months/m[number($month)]"/>
Where $month can be the string 1 .. 12.
This works just fine with XSLT 1.0, but for some strange
reason, it does not work for XSLT2.
Well, it shouldn't work in 1.0, because you're not allowed to use a result
tree fragment as a node-set.
And it should work in 2.0 (with minor corrections like matching the start
and end tag of xsl:variable, and removing the $ from name="$months)
Stylesheet:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:param name="month"/>
<xsl:template match="/">
<xsl:variable name="months">
<m>January</m><m>February</m><m>March</m><m>April</m>
<m>May</m><m>June</m><m>July</m><m>August</m>
<m>September</m><m>October</m><m>November</m><m>December</m>
</xsl:variable>
<xsl:value-of select="$months/m[number($month)]"/>
</xsl:template>
</xsl:stylesheet>
Saxon 8.8 command:
java net.sf.saxon.Transform test.xsl test.xsl month=8
output: August
Saxon 6.5.5 command:
java -jar saxon.jar test.xsl test.xsl month=8
output:
Error at xsl:value-of on line 19 of file:/c:/temp/test.xsl:
To use a result tree fragment in a path expression, either use
exsl:node-set() or specify version='1.1'
Michael Kay
http://www.saxonica.com/
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--