XSLT patterns

This section gives an informal description of the syntax of XSLT patterns. For a formal specification, see the XSLT recommendation.

The documentation here describes patterns in XSLT 3.0. There are extensions in the draft 4.0 specifications, which are mentioned here when appropriate: be aware, however, that these may change.

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 in XSLT 3.0 is a subset of that for the XPath syntax. In XSLT 3.0 there are two kinds of pattern:

XSLT 4.0 introduces another kind of pattern, the type pattern. This simply matches items by their item type, introduced with the ~ (tilde) character. For example ~map(*) matches any map, and ~xs:string matches a string. The type can be followed by predicates, for example ~map(*)[?age gt 21] matches any map having a field with key age whose value exceeds 21.

Patterns are used primarily in the match attribute of the xsl:template element. They are also used in the count and from attributes of xsl:number, the match attribute of xsl:key, and the group-starting-with and 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 3.0 syntax.