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

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

The equals operator
=
returns false if either or both operands are NaN, and the not-equals operator
!=
returns true if either or both operands are NaN. Watch out for the apparent contradictions this leads to; for example,
$x = $x
can be false, and
$x < $y
doesn't necessarily give the same answer as
$y > $x
.

The simplest way to test whether a value
$x
is NaN is:

if ($x!=$x) then …

If this seems too obscure for your taste, then provided you know that
$x
is numeric you can write:

if (string($x)=‘NaN’) then

If you are familiar with null values in SQL, some of this logic might seem familiar, but there are some subtle differences. For example, in SQL the condition
null = null
has the value null, so that
not(null = null)
is also null, while in XPath
NaN = NaN
is false, so that
not(NaN = NaN)
is true.

Other books

Heathcliff's Tale by Emma Tennant
His Need by Ann King
Merry Gentry 05 - Mistral's Kiss by Laurell K. Hamilton
Remnant Population by Elizabeth Moon
07 Seven Up by Janet Evanovich
The Last Girl by Kitty Thomas
The Shop by J. Carson Black