This section gives an informal description of the syntax of XSLT patterns. For a formal specification, see the XSLT recommendation. XSLT 3.0 introduces extensions, described below, to allow atomic values as well as nodes to be matched, and removes a number of restrictions. Saxon (since version 9.6) implements these extensions.
Patterns define a condition that an item may or may not satisfy: an item either matches the pattern, or it does not. The syntax of patterns is a subset of that for the XPath expressions. In XSLT 3.0 there are two kinds of pattern:
Path patterns. Formally, a node matches a path pattern if it is a member of the node set selected by the corresponding expression, with some ancestor of the node acting as the current node for evaluating the expression. For example a
<TITLE>node matches the pattern
TITLEbecause it is a member of the node set selected by the expression
TITLEwhen evaluated at the immediate parent node.
Predicate patterns, for example
.[@x = 2]. A predicate pattern consists of "." followed by zero or more predicates, and it matches an item if all the predicates are true when applied to that item. Predicate patterns can be used to match atomic values and maps as well as nodes.
Patterns are used primarily in the
match attribute of
the xsl:template element. They are also
used in the
from attributes of xsl:number, the
attribute of xsl:key, and the
group-ending-with attributes of xsl:for-each-group.
The next page gives some examples of match patterns and their meaning. This is followed by a page that gives a summary of the XSLT 2.0 syntax, and another page that describes the extensions to patterns in XSLT 3.0.