Pattern syntax
Saxon supports the full XSLT syntax for patterns. The rules below describe a simplified form of this syntax (for example, it omits the legal but useless pattern '@comment()'):
pattern ::= path ( '|' path )* path ::= anchor? remainder? (Note 1) anchor ::= '/' | '//' | id | key id ::= 'id' '(' value ')' key ::= 'key' '(' literal ',' value ')' value ::= literal | variable-reference remainder ::= path-part ( sep path-part )* sep ::= '/' | '//' path-part ::= node-match predicate+ node-match ::= kind-match | type-match kind-match ::= element-match | text-match | attribute-match | pi-match | any-node-match element-match ::= 'child::'? ( name | '*' ) text-match ::= 'text' '(' ')' attribute-match ::= ('attribute::' | '@') ( name | '*' ) pi-match ::= 'processing-instruction' '(' literal? ')' any-node-match ::= 'node' '(' ')' type-match ::= ('element'|'attribute') '(' ('*'|node-name) (',' type-name) ')' predicate ::= '[' ( boolean-expression | numeric-expression ) ']'Note 1: not all combinations are allowed. If the anchor is '//' then the remainder is mandatory.
The form of a literal is as defined in expressions; and a predicate is itself a boolean
or numeric expression. As with predicates in expressions, a numeric predicate [P]
is shorthand
for the boolean predicate [position()=P]
.
Informally, a pattern consists of either a single path or a sequence of paths separated by vertical bars. An element matches the match-pattern if it matches any one of the paths.
A path consists of a sequence of path-parts separated by either "/" or "//". There is an optional separator ("/" or "//") at the start; a "//" has no effect and can be ignored. The last path-part may be an element-match, a text-match, an attribute-match, a pi-match, or a node-match; in practice, a path-part other than the last should be an element-match.
The axis syntax child::
and attribute::
may also be used in patterns, as described in the XSLT
specification.