Re: [xsl] Key/Use

Subject: Re: [xsl] Key/Use
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Wed, 5 Sep 2001 16:01:32 -0400
[<Kevin_Gutch@xxxxxxxxxxx>]


>  <xsl:key name="lookup" match="row" use="US_layer_name"/>
>
> All I actually want to do is  pass in a parameter from a servlet and use a
> dynamic key value to be used in a XSLT LookUp Table. Everything works I
> just want to use a dynamic lookup table so I do not have to have more than
> one lookup table. So basically US could be BG(Great Britian),CN(Canada)
> etc.
>

Isn't this more or less what you were after?  The country could be passed in
as a global parameter instead of being a variable.  This example makes use
of an index (which you were asking for), and you can pass in the country
dynamically.  Here the index isn't buying you much, but if the example were
more complicated (and long) it might.   The point is to use the variable at
lookup time, not when you define the key.

XML:
<root>
<row country='US'>us1</row>
<row country='US'>us2</row>

<row country='GB'>gb1</row>
<row country='GB'>gb2</row>
<row country='GB'>gb3</row>

<row country='FR'>fr1</row>
<row country='FR'>fr2</row>
</root>

XSLT:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:variable name='c' select='"GB"'/>
<xsl:key name='country' match='row' use='@country'/>

<xsl:template match="/">
<results>
   <xsl:for-each select='key("country",$c)'>
        <xsl:value-of select='.'/>
   </xsl:for-each>
</results>
</xsl:template>
</xsl:stylesheet>

Output:

<results>gb1gb2gb3</results>


Cheers,

Tom P


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread