Re: [xsl] Can xsl:key use a globally declared variable?

Subject: Re: [xsl] Can xsl:key use a globally declared variable?
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 16 Nov 2018 15:53:17 -0000
On 16.11.2018 16:47, Costello, Roger L. costello@xxxxxxxxx wrote:

I declare a variable to hold the airports document:

<xsl:variable name="airport-file" select="doc('airports.xml')"/>

I declare an xsl:key to index the rows, using the <icao> element to identity the desired <row>:

<xsl:key name="airports-with-icao" match="$airport-file/airports/row" use="icao"/>


It suffices to declare the key with the right match pattern independent of the document e.g.
match="airports/row"


In a template I declare a variable to hold the icao of the desired airport:

<xsl:variable name="airport-icao" select="'KBOS'"/>

I use the key() function to obtain the desired <row>:

<xsl:sequence select="key('airports-with-icao', $airport-icao)" />

But you need to pass in the document (or subtree in general) you want to search as the third argument to the "key" function with


key('airports-with-icao', $airport-icao, $airport-file)

if you don't want to search the document of the current context node.

Current Thread