Name

key()

References a relation defined with an <xsl:key> element. Conceptually, the key() function works similarly to the id() function, although keys are more flexible than IDs.

Syntax

[1.0] node-set key(string, object)
[2.0] node()* key(xs:string, xs:anyAtomicType*)
[2.0] node()* key(xs:string, xs:anyAtomicType*, node())

Inputs

[1.0] The name of the key (defined by an <xsl:key> element) and an object. If the object is a node-set, then the key() function applies itself to the string value of each node in the node-set and returns the node-set of the result of all those key() function invocations. If the object is any other type, it is converted to a string as if by a call to the string() function.

[2.0] The name of the key (an xs:string) and a sequence of search values. An optional third argument limits the search to all the nodes that have the specified node as an ancestor-or-self node. The third argument lets us limit the search results to a particular group of nodes.

Output

[1.0] A node-set containing the nodes in the same document as the context node whose values for the requested key match the search argument(s). In other words, if our stylesheet has an <xsl:key> element that defines a key named postalcodes based on the <postalcode> child of all <address> elements in the current document, the function call key(postalcodes, '34829') returns a node-set containing all the <address> elements with a <postalcode> element whose value is 34829.

[2.0] A sequence of nodes, each of which matches ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.