XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (414 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
10.14Mb size Format: txt, pdf, ePub

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

. This was probably an oversight by the language designers, and the restriction has been lifted in XPath 2.0. As you would expect, this expression tests whether the parent element node has a
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.

Other books

Sailing from Byzantium by Colin Wells
Detective Partners by Hopkins, Kate
Intermezzo by Delphine Dryden
The London Eye Mystery by Siobhan Dowd
Requiem by Jamie McGuire
Pleasing the Colonel by Renee Rose
False Impression by Jeffrey Archer
Perfect for You by Ashelyn Drake