xml editor

Supported platforms

Compatible with Windows7 & Mac OS X Snow Leopard

Ready for data server software
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Keeping a map in my XSL


Subject: Re: [xsl] Keeping a map in my XSL
From: andrew welch <andrew.j.welch@xxxxxxxxx>
Date: Tue, 13 Sep 2005 19:40:26 +0100

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
Keywords
xsl
XML Editor | XML Author | WYSIWYG Editors | Schema Editor | XSD Documentation | XSL/XSLT Editor | XQuery | XML Databases | SVN Client
© 2002-2011 SyncRO Soft Ltd. All rights reserved. | Sitemap | Privacy Policy | This website was created & generated with <oXygen/>®XML Editor