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

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

The
PathExpr
construct is probably the most complex construct in the XPath language. The actual production rules are quite complicated and hard to follow, but they are there to make path expressions easy to write, especially if you are familiar with Unix-style path names for directories and files. Most of the syntactic complications arise from the range of abbreviations that are permitted, so we will cover the basic constructs and operators first, and introduce the syntactic abbreviations later.

Changes in XPath 2.0

In XPath 2.0, the syntax of path expressions has been generalized so that any expression can be used as a step in a path. For example,
doc(‘a.xml’)/id(‘Z123’)
is now a valid path expression. This makes
/
behave in a similar way to other binary operators. An expression used on the left-hand side of the
/
operator can be any expression that returns a sequence of nodes; the expression used on the right of
/
(in effect, the last step in a simple mapping expression) can also return atomic values.

In XPath 1.0, path expressions were defined to return a node-set, that is, a set of nodes with no duplicates, in no particular order. XSLT 1.0, however, always processed the resulting nodes in document order. The XPath 2.0 data model does not support node-sets as such, but by redefining path expressions to return a sequence of nodes in document order with no duplicates, the result is effectively the same.

There are new facilities in XPath 2.0 to select nodes according to their schema-defined type, rather than selecting them only by name. These facilities are described in detail in Chapter 11.

The constructs
.
and
..
can now be followed by predicates.

The axes are unchanged from XPath 1.0, with one exception: the namespace axis has been deprecated. This means that XPath 2.0 implementations may or may not make this axis available. All the information that was available by using the namespace axis in XPath 1.0 (that is, the ability to find all the namespaces declared for any given element) can now be obtained through two new functions:
in-scope-prefixes()
and
namespace-uri-for-prefix()
. These functions are described in Chapter 13. The reason for replacing the namespace axis with these functions is to allow implementations more flexibility to implement namespaces efficiently. Modeling the information using namespace nodes imposed burdens on the implementation that offered no real benefit to users; for example, the ability to do union and intersection operations on sets of namespace nodes, and the ability to get back from a namespace node to its parent element.

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

Other books

Getaway Girlz by Joan Rylen
Awakening Amelia by Kate Pearce
Trophy Kid by Steve Atinsky
Reign of Iron by Angus Watson
Faking Faith by Josie Bloss
Glass Collector by Anna Perera
Simple Choices by Nancy Mehl
Bloodline by Maggie Shayne