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

Heather Graham by Siren from the Sea
Little Bee by Chris Cleave
Four Wheeled Hero by Malcolm Brown
Steadfast by Claudia Gray
The Goblin's Curse by Gillian Summers
Master of Shadows by Angela Knight
Perfect Gallows by Peter Dickinson
Sweet Surprise by Candis Terry
Cold Judgment by Joanne Fluke