Heres the thing though. I can't have the map in my source XML, I want it
in my source XSLT.
Is there a way to set the map in an XML document and include it in my
Source XSL and then
Reference it in the XSLT using the key() function?
-Thanks,
Kevin
-----Original Message-----
From: andrew welch [mailto:andrew(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com]
Sent: Tuesday, September 13, 2005 12:02 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Keeping a map in my XSL
On 9/13/05, Kevin L. Cobb <kevin(_dot_)cobb(_at_)emergint(_dot_)com> wrote:
I want to be able to set a variable that is retreived from my XML I am
parsing to a mapped values. For example, lets say I have an XML map
that looks like this:
<map>
<key>12345</key><value>abcde</key>
<key>78910</key><value>lmnop</value>
</map>
My source XML has the value '12345' in a certain field. I retreive the
field as usual in XSL and then I want to get the mapped value of this
field. The map above is "included" in my XSL. Is there a best way to
do this in XSL?
yes, first restructure your map as associating a key and value by
position is a bad idea, much better to use attributes:
<map>
<key name="12345" value="abcde"/>
<key name="78910" value="lmnop"/>
</map>
then define a key to return a value for a given name:
<xsl:key name="mappings" match="key" use="@name"/>
then in xslt 1.0 use:
<xsl:variable name="lookup" select="the_name_you_want_lookup"/>
<xsl:for-each select="$map">
<xsl:value-of select="key('mappings', $lookup)/@value"/>
</xsl:for-each>
in 2.0 you don't have the hassle of switching the context node because
key() can take it as the third argument:
<xsl:value-of select="key('mappings', the_name_you_want_to_lookup,
$mappings)/@value"/>
cheers
andrew
--~------------------------------------------------------------------
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>
--~--
--~------------------------------------------------------------------
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>
--~--