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

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

Arithmetic

Arithmetic operations in XPath 2.0 may be carried out using integer, decimal, or single- or double-precision floating point. This means the result may be slightly different from XPath 1.0, which always used double-precision floating point. XPath 2.0 in backward-compatibility mode also uses double-precision floating point for all arithmetic.

The Empty Sequence

In XPath 1.0, if an empty node-set was used as an operand to a function or operator that expected a string, it was automatically converted to the zero-length string. Similarly, if the operator or function expected a number, it was automatically converted to NaN (not a number).

In XPath 2.0 the functions in the core library that expect a string argument reproduce this behavior. This is not a built-in feature of the language, it is simply part of the way these particular functions are specified, but this is sufficient to prevent compatibility problems.

However, the corresponding change for numeric operators and functions has not been made. For example, if the attribute
A
does not exist, then the expression
@A+1
returned NaN under XPath 1.0, but returns an empty sequence under XPath 2.0. If you output this value by converting it to a string, the result will be a zero-length string instead of the string
NaN
.

Although the empty sequence plays a significant role as a null value in XPath 2.0, most practical expressions are unaffected by the change.

Error Semantics for
and
and
or

In XPath 1.0 it was defined, in the case of an expression such as
A and B
, that
B
would not be evaluated if
A
was false. Similarly, with
A or B
,
B
would not be evaluated if
A
was true.

This meant that you could safely write an expression such as:

($cols = 0) or ($n div $cols > 100)

XPath 2.0 no longer gives this guarantee. The operands of
and
and
or
can now be evaluated in either order, or in parallel. In the example above, this means that the division might be evaluated, and cause an error, in the case where
$cols
is zero.

Other books

Death of a Dreamer by Beaton, M.C.
Unnatural by Michael Griffo
Guilt by Association by Susan R. Sloan
Origin by Jack Kilborn
The Boat House by Pamela Oldfield
Trouble Vision by Allison Kingsley
Water Lily in July by Clare Revell
On The Banks Of Plum Creek by Wilder, Laura Ingalls