Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
More generally, runtime errors can also occur when evaluating a predicate in a pattern. For example, matching the pattern
//book[@price div 0 = 0]
could cause a runtime error (division by zero). The spec is open ended about these; it makes it clear that whether or not a particular error is ever reported will depend on the order in which the processor chooses to test the different patterns, and even then, on its evaluation strategy for a particular pattern. It also allows processors to ignore such errors, simply behaving as if the pattern does not match.
The other problem that occurs with parentless nodes is that using the definition as we have it so far, the pattern
match = “ex”
means
match = “child::e”
and would match an
e
should match every
chapter / para
should match every
The way that the formal definition of patterns has been bent to meet this requirement is somewhat tortuous. It is done by introducing two new axes,
child-or-top
, and
attribute-or-top
, and using these axes in the first step of a
RelativePathPattern
in place of the usual
child
and
attribute
axes. The
child-or-top
axis selects the children of the context node, unless the context node is a parentless element, text node, comment, or processing instruction, in which case it selects the parentless context node itself. Similarly, the
attribute-or-top
axis selects the context node itself if it is a parentless attribute node. Given these two extra axes, the equivalence between patterns and XPath expressions continues to hold. (These axes, of course, are purely notional. You can't use them explicitly either in an XPath expression or in a pattern.)
Note that this refinement does not apply to patterns starting with
/
. The pattern
//book
, which in XSLT 1.0 matched exactly the same nodes as the pattern
book
, now has a slightly different meaning: it selects only
match = “//book”
is quite likely to be less efficient than
match = “book”
because the system now has to check what kind of node is at the root of the tree.