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

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

Most people writing XPath expressions use this abbreviation all the time without really thinking about it. In fact, it's rare to see
child::
spelled out explicitly. But I do sometimes like to write the full form to alert the reader to what's going on. For example, the expression
record[*]
selects all

elements that have one or more child elements. I sometimes write this as
record[child::*]
so that anyone reading the code can see more clearly what it means. The full syntax for the expression, of course, is
child::record[child::*]
, and you could spell it out even more explicitly by writing
child::record[exists(child::*)]
. (The
exists()
function is in Chapter 13).

There's one exception to the general rule that if you don't specify an axis, you get the child axis. This is when you use a
NodeTest
of the form
attribute(…)
or
schema-attribute(…)
. This kind of
NodeTest
is used when testing the schema-defined type of an attribute node; it is described in detail in Chapter 11. Because the
NodeTest
makes it clear that you are looking for attributes rather than child elements, the system in this case chooses the attribute axis as the default. This avoids your having to write
attribute::attribute(*)
or
@attribute(X)
, both of which read rather oddly, though they are both legal and logical.

Other books

Unspoken 2 by A Lexy Beck
Betrayed by Love by Marilyn Lee
Hitler's Olympics by Christopher Hilton
Miracle Cure by Harlan Coben
Undersea Fleet by Frederik & Williamson Pohl, Frederik & Williamson Pohl
Half World by Hiromi Goto
Child of the Dead by Don Coldsmith
Manly Wade Wellman - John the Balladeer SSC by John the Balladeer (v1.1)
The Widow and the Orphan by J. Thomas-Like
Dangerously Bound by Eden Bradley