Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Writing
not(..)
is a simple way of testing whether the context node is the root.
As explained in Chapter 2, the element containing an attribute is considered to be the parent of the attribute, even though the attribute is not a child of the element. Unlike biological relationships, in XPath the
parent
and
child
relationships are not the inverse of each other. This allows you to use an expression such as
idref(‘abc’)/..
to select the elements that have an
IDREF
attribute with the value
abc
(the
idref()
function is described in Chapter 13; it is one of the few constructs that make it natural to select an attribute node without going via its parent element.)
In XPath 1.0 the expression
..
could not be followed by a predicate: you could not write
color
attribute whose value is
black
.
Examples in Context
Expression | Effect |
exists(..) | Tests whether the context node has a parent (in other words, whether it is the root of a tree). |
../@name | Selects the name attribute of the parent of the context node. |
The Root Expression
/
I've invented the term
root expression
to refer to the expression
/
, when used on its own (that is, when used as an expression, rather than as an operator). This doesn't actually have a name in the XPath syntax, and I feel it's important enough to give it one.