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

RE: How to access an array from a node-set variable

Subject: RE: How to access an array from a node-set variable
From: "Andrew Welch" <ajwelch@xxxxxxxxxxxxxxx>
Date: Mon, 11 Jul 2005 09:43:45 +0100
monthname access
> This is my data:
>
> <Date>2004-08-02</Date>
>
> Which I would like to display as follows:
>
> 02 ao{t 2004
>
> I have placed an array of French month names in a node-set:
>
> <xsl:variable name="FrenchMonth">
>     <MonthNames>
>         <MonthName MonthNumber="01">janvier</MonthName>
>         <MonthName MonthNumber="02">f&#233;vrier</MonthName>
>         <MonthName MonthNumber="03">mars</MonthName>
>         <MonthName MonthNumber="04">avril</MonthName>
>         <MonthName MonthNumber="05">mai</MonthName>
>         <MonthName MonthNumber="06">juin</MonthName>
>         <MonthName MonthNumber="07">juillet</MonthName>
>         <MonthName MonthNumber="08">aou&#251;t</MonthName>
>         <MonthName MonthNumber="09">septembre</MonthName>
>         <MonthName MonthNumber="10">octobre</MonthName>
>         <MonthName MonthNumber="11">novembre</MonthName>
>         <MonthName MonthNumber="12">d&#233;cembre</MonthName>
>         </MonthNames>
> </xsl:variable>
>
> And I created the following template:
>
> <xsl:template name="FrenchDate">
>     <xsl:variable name="year" select="substring-before(., '-')"/>
>     <xsl:variable name="month" select="substring(.,6,2)"/>
>     <xsl:variable name="day" select="substring(.,9,2)"/>
>         <xsl:value-of select="$day"/>
>         <xsl:text> </xsl:text>
>         <xsl:value-of
> select="exsl:node-set($FrenchMonth)/MonthName[@MonthNumber=$month]"/>
>         <xsl:text> </xsl:text>
>         <xsl:value-of select="$year"/>
> </xsl:template>
>
> Which I attempt to call as follows:
>
> <xsl:template match="/">
>     <xsl:for-each select="//Date">
>         <xsl:call-template name="FrenchDate"/>
>         <br/>
>     </xsl:for-each>
> </xsl:template>
>
> How come it doesn't work?

Because you've used:

 <xsl:value-of
select="exsl:node-set($FrenchMonth)/MonthName[@MonthNumber=$month]"/>

And you variable definition is:

 <xsl:variable name="FrenchMonth">
  <MonthNames>
    <MonthName MonthNumber="01">janvier</MonthName>

..so you've left out <MonthNames> in the path.  Correct that and it all should
work fine.

cheers
andrew

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.