Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
If you write a stylesheet with a lot of template rules, then the time taken to find the particular rule to apply to a given node can make a significant difference. The exact way in which different XSLT processors do the matching may vary, but one thing you can be sure of is that patterns containing complex predicates will add to the cost.
Conflict Resolution
When a pattern is used in the definition of a template rule, it is possible that several patterns may match the same node. There are rules for resolving this conflict, which are described in the section
Choosing a Template Rule
in the entry for
default priority
of the pattern, which is determined from the way it is written.
The default priority is decided according to the following rules. A numerically higher value indicates a higher priority. Note that some of the priorities are fractional, and some are negative.
If the pattern is a union of two or more patterns (
P1|P2
), then the processor treats it as if there were two completely separate template rules specified, one for
P1
and one for
P2
, and it calculates the default priority of
P1
and
P2
independently, using the rules in the table.
If the pattern starts with an axis specifier (
child::
,
attribute::
or
@
)
, this does not affect the priority.
Pattern Syntax | Default Priority |
document-node(schema-element(QName)) document-node(element(QName, QName)) schema-element(QName) element(QName, QName) schema-attribute(QName) attribute(QName, QName) | +0.25 |
QName document-node(element(QName)) document-node(element(*, QName)) | 0.0 |
element(QName) element(*, QName) attribute(QName) attribute(*, QName) processing-instruction(Literal) processing-instruction(NCName) | |
NCName:* *:NCName | –0.25 |
/ document-node() document-node(element()) document-node(element(*)) * element() element(*) attribute() attribute(*) text() comment() processing-instruction() node() | −0.5 |
Otherwise | +0.5 |
These default priorities are carefully chosen to reflect the selectivity of the pattern: