RE: [xsl] Simple lookup in XSLT2

Subject: RE: [xsl] Simple lookup in XSLT2
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 14 Nov 2006 10:57:55 -0000
> 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)


<xsl:stylesheet version="1.0"
<xsl:output method="text"/>

<xsl:param name="month"/>

<xsl:template match="/">

<xsl:variable name="months">

<xsl:value-of select="$months/m[number($month)]"/>


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


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

Current Thread