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

Haunted London by Underwood, Peter
Seducing an Angel by Mary Balogh
Snatchers (A Zombie Novel) by Whittington, Shaun
Tea with Jam and Dread by Tamar Myers
Extraordinary Powers by Joseph Finder
Nate by Delores Fossen
Gathering of Waters by Bernice L. McFadden
Warlord: Dervish by Tony Monchinski