xsl-list
[Top] [All Lists]

Re: Keeping a map in my XSL

2005-09-13 11:40:26
On 9/13/05, Nathan Young (natyoung) <natyoung(_at_)cisco(_dot_)com> 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[(_at_)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>

--~------------------------------------------------------------------
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>
--~--



<Prev in Thread] Current Thread [Next in Thread>