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

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

The value of the context item is not changed in the body of a
for
expression (described in Chapter 10). It is therefore wrong to write something like:

sum(for $x in //item return ./@price * ./@qty)

Instead, you need to write:

sum(for $x in //item return $x/@price * $x/@qty)

Changes in XPath 2.0

In XPath 1.0, the
.
symbol was an abbreviation for the
Step
self::node()
. This restricted its value to being a reference to a node (never an atomic value), and it also imposed certain other restrictions; for example, it was not possible to apply a predicate to
.
. In XPath 2.0 you can use constructs such as
.[*]
which returns the context item only if it is a node that has a child element.

In XPath 1.0,
.
was never undefined—it always had a value, and the value was always a single node. In XPath 2.0, there are many situations in which it can be undefined; for example, it is undefined on entry to a function body written in XSLT or XQuery.

Usage

The two places where
.
is commonly used are:

Other books

Lovers and Newcomers by Rosie Thomas
5000 Year Leap by Skousen, W. Cleon
The Dirty Secrets Club by Meg Gardiner
Blooming in the Wild by Cathryn Cade
The List by Joanna Bolouri
Frantic by Jerry B. Jenkins
Off the Wagon (Users #2) by Stacy, Jennifer Buck
College Hacks by Keith Bradford