Patterns in XSLT 3.0
XSLT 3.0 introduces a new pattern syntax .[expression]
: this matches any
item for which the effective boolean value of the expression (evaluated with that
item as the context item) is true. For example .[. gt 0]
will match any
item (either an atomic number, or a node that atomizes to a number) if it is greater
than zero, while .[nilled()]
matches any element that is nilled
(@xsi:nil='true'
). Note that if the predicate cannot be evaluated
because the item is of the wrong type, no error occurs, the pattern simply does not
match.
Other XSLT 3.0 extensions to patterns that are implemented since Saxon 9.6 include the following:
-
The
intersect
andexcept
operators are allowed at the top level: for examplematch="* except br"
. -
Parentheses may be used in conjunction with a predicate, for example
match="(//para)[1]"
. -
Any downwards axis may be used in a pattern, for example
descendant
ordescendant-or-self
. -
A pattern can consist simply of a variable reference:
match="$v"
. This matches any node that is present in the value of$v
. For a pattern used in template matching, this will necessarily be a global variable. -
A pattern can also be a path starting with a variable reference:
match="$v//book"
matches anybook
element that is a descendant of a node in$v
. -
Patterns can be restricted to match nodes within a particular document, for example
match="doc('books.xml')//book
. (Note that Saxon will only read the document once, so this is not an expensive operation.)