xsl-list
[Top] [All Lists]

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

2018-11-16 09:53:23
On 16.11.2018 16:47, Costello, Roger L. costello(_at_)mitre(_dot_)org 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.

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

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