Next / Previous / Contents / Shipman's homepage

12.5. key(): Refer to an index entry

This function is used to retrieve a set of nodes from anywhere in the document, using the index specified elsewhere by an xsl:key element.

The calling sequence is:

    key(keyName, keyValue )

where keyName matches the name attribute of an xsl:key element, and keyValue is a string. The result is a node-set containing all the nodes whose value for that key matches keyValue.

Here's an example. Suppose we declare a key like this:

    <xsl:key name="river-map-key" match="river" use="@map"/>

Then we might process a set of river elements that have an attribute map="Puerco" with this query:

    <xsl:apply-templates select="key('river-map-key', 'Puerco)"/>