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.17Mb 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

Be Mine for Christmas by Alicia Street, Roy Street
A Class Apart by Susan Lewis
Scratch Monkey by Charles Stross
The Week at Mon Repose by Margaret Pearce
Michael O'Leary by Alan Ruddock
Midwives by Chris Bohjalian
The Elizabeth Papers by Jenetta James