Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
With the first form,
PatternStep
, a node matches the pattern if it satisfies the conditions (node name, node kind, and predicates) defined in the
PatternStep
. The simplest and most common form of
PatternStep
is simply an element name, for example
title
.
With the second form,
RelativePathPattern
/
PatternStep
, a node matches the pattern if it satisfies the conditions (node name, node kind, and predicates) defined in the
PatternStep
, and if its parent node matches the
RelativePathPattern
. This
RelativePathPattern
may in turn include conditions that the parent node's parent or ancestor nodes must satisfy.
With the third form,
RelativePathPattern
//
PatternStep
, a node matches the pattern if it satisfies the conditions (node name, node kind, and predicates) defined in the
PatternStep
, and if it has an ancestor that matches the
RelativePathPattern
. This
RelativePathPattern
may in turn include conditions that the ancestor node's parent or ancestor nodes must satisfy.
Usage
Notice that although there is an equivalence between
RelativePathPattern
in the pattern language and
RelativePathExpr
in the expression language, the meaning of a
RelativePathPattern
is most easily explained by examining the
PatternSteps
from right to left, starting at the node being tested and working up through its ancestors, if necessary; this is despite the fact that the meaning of a
RelativePathExpr
is explained by considering the
Steps
from left to right, starting at the context node. It's likely that most implementations will adopt a strategy similar to the algorithm as I've explained it here.
Generally speaking, there is no point in making patterns any more selective than is necessary. For example, if a In theory, everything you can do in a
, then there is no point in specifying the pattern as
table/row
—you might just as well use the simpler pattern
row
.
RelativePathPattern
could be done in a single
PatternStep
, because the pattern
A/B
means exactly the same as
B[parent::A]
and the pattern
A//B
means exactly the same as
B[ancestor::A]
. However, where several steps are present, the form using
/
and
//
operators is a lot easier to read.Other books