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

Re: Keeping a map in my XSL

Subject: Re: Keeping a map in my XSL
From: andrew welch <andrew.j.welch@xxxxxxxxx>
Date: Tue, 13 Sep 2005 19:40:26 +0100
Re:  Keeping a map in my XSL
On 9/13/05, Nathan Young (natyoung) <natyoung@xxxxxxxxx> wrote:
> Hi.
>
> Kevin, I've done something like what you want to do using the document
> function and xpaths.  I agree with Andrew's suggestion about not relying
> on document order to associate key/value pairs, but we have values that
> can contain elements so we use something more like:
>
> <map>
>    <key name="1">value of name 1</key>
>    <key name="7">value of name 7</key>
> </map>
>
> That's in a separate file from the xsl (say map.xml).
>
> Then in the xsl you can use:
>
> <xsl:variable name="map" select="document('map.xml')"/>
>
> To get then value for 1 you can use:
>
> <xsl:value-of select="$map//key[@name='1']/>
>
> Andrew would your xsl:key solution apply to this?  If so how?

Sure, define the key:

<xsl:key name="mappings" match="key" use="@name"/>

then:

<xsl:for-each select="$map">
  <xsl:value-of select="key('mappings', '1')"/>
</xsl:for-each>

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.