[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Simple lookup in XSLT2

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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.