SAXONICA

Saxon Documentation
Full Contents
About Saxon
Changes in this Release
Notices
Using XSLT 2.0
Using XQuery
Handling Source Documents
XML Schema Processing
XPath API for Java
Saxon on .NET
Extensibility
Saxon Extensions
Sample Saxon Applications
The Saxon SQL Extension
XSLT Elements
| Introduction
| xsl:analyze-string
| xsl:apply-imports
| xsl:apply-templates
| xsl:attribute
| xsl:attribute-set
| xsl:call-template
| xsl:character-map
| xsl:choose
| xsl:comment
| xsl:copy
| xsl:copy-of
| xsl:decimal-format
| xsl:document
| xsl:element
| xsl:fallback
| xsl:for-each
| xsl:for-each-group
| xsl:function
| xsl:if
| xsl:include
| xsl:import
| xsl:import-schema
» | xsl:key
| xsl:matching-substring
| xsl:message
| xsl:namespace
| xsl:namespace-alias
| xsl:next-match
| xsl:non-matching-substring
| xsl:number
| xsl:otherwise
| xsl:output
| xsl:output-character
| xsl:param
| xsl:perform-sort
| xsl:preserve-space
| xsl:processing-instruction
| xsl:result-document
| xsl:sequence
| xsl:sort
| xsl:strip-space
| xsl:stylesheet
| xsl:template
| xsl:text
| xsl:value-of
| xsl:variable
| xsl:when
| xsl:with-param
| Literal Result Elements
| XSLT Patterns
XPath 2.0 Expression Syntax
Function Library
Standards Conformance

# xsl:key

The `xsl:key` element is used at the top level of the stylesheet to declare an attribute, or other value, that may be used as a key to identify nodes using the `key()` function within an expression. Each xsl:key definition declares a named key, which must match the name of the key used in the `key()` function.

The set of nodes to which the key applies is defined by a pattern in the match attribute: for example, if `match="ACT|SCENE"` then every `ACT` element and every `SCENE` element is indexed by this key.

The value of the key, for each of these matched elements, is determined by the `use` attribute. This is an expression, which is evaluated for each matched element. If the expression returns a node-set, the typed value of each node in this node-set acts as a key value. For example, if `use="AUTHOR"`, then each AUTHOR child of the matched element supplies one key value.

Note that:

1. Keys are not unique: the same value may identify many different nodes

2. Keys are multi-valued: each matched node may have several (zero or more) values of the key, any one of which may be used to locate that node

3. Keys can only be used to identify nodes within a single XML document: the key() function will return nodes that are in the same document as the current node.

All three attributes, `name`, `match`, and `use`, are mandatory.

The optional `collation` attribute can be used when comparing strings.

Saxon does not yet allow the `xsl:key` element to contain a sequence constructor in place of the `use` attribute.

Next