As Michael correctly stated, there were a bunch of errors in the small
fragment I wrote (lack of QA in my e-mail's - not the actual code) and
yes, I was of course using XSLT 1.1 (obviouly with Saxon 6.5.5)
However even with typecasting it did not work with XSLT2 (using Saxon
8.8). I have not tried out Davids proposal yet, but that might be a
solution. At least there was not a major conceptual change betwwen XSLT1
and XSLT2 behaviour I had missed.
Thanks guys, I just have to keep digging until I find the culprit.
Regards,
Jens
On Tue, 14 Nov 2006, Michael Kay wrote:
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>
--~--
Regards,
Jens
------------------------------------------------------------------------
Jens Stavnstrup Phone :
Danish Defence Research Establishment Voice : + 45 - 39 15 17 97
Ryvangs Alle 1 - P.O. Box 2715 Fax : + 45 - 39 29 15 33
DK - 2100 Copenhagen O. E-Mail (Internet) :
Denmark js(_at_)ddre(_dot_)dk
Jabber/XMPP:
stavnstrup(_at_)jabber(_dot_)org
------------------------------------------------------------------------
--~------------------------------------------------------------------
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>
--~--