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

Brit Party by Desiree Holt, Ashley Ladd, Brynn Paulin
Shipwrecks by Akira Yoshimura
Perfect Touch by Elizabeth Lowell
Flight of the King by C. R. Grey
Coach Amos by Gary Paulsen
Goblin Quest by Philip Reeve
One Hour to Midnight by Shirley Wine
Lucky Leonardo by Jonathan D. Canter