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
6.21Mb 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

Believing Lies by Everleigh, Rachel
TRUTH by Sherri Hayes
An American Bulldog by Liz Stafford
The Woman I Wanted to Be by Diane von Furstenberg
The Night Belongs to Fireman by Jennifer Bernard
SURRENDER IN ROME by Bella Ross
Blood and Royalty by M. R. Mathias