Unabbreviated Location Paths
Up until this point, we’ve been using what are called abbreviated location paths . These are easy to type, not usually verbose, and very familiar to most people. They’re also the kind of XPath expression that works best for XSLT match patterns. However, XPath also offers an unabbreviated syntax for location paths, which is more verbose but perhaps less cryptic and definitely more flexible than abbreviated location paths.
Every location step in a location path has two required parts, an axis and a node test, and one optional part, the predicates. The axis tells you which direction to travel from the context node to look for the next nodes. The node test tells you which nodes to include along that axis, and the predicates further reduce the nodes according to some expression.
In an abbreviated location path, the axis and the node test are
combined, while in an unabbreviated location path, they’re separated
by a double colon (::)
.
For example, the abbreviated location path people/person/@id
is composed of three
location steps. The first step selects people
element nodes along the child axis.
The second step selects person
element nodes along the child axis. The third step selects id
attribute nodes along the attribute axis.
When rewritten using the unabbreviated syntax, the same location path
is child::people/child::person/attribute::id
.
These full, unabbreviated location paths may be absolute if they start from the root node, just as abbreviated paths ...
Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.