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

Call Out by L.B. Clark
The Glades by Clifton Campbell
The Lewis Man by Peter May
Killer Crust by Chris Cavender
Venom and Song by Wayne Thomas Batson
Dangerous Designs by Kira Matthison
Love Is a Breeze by Purcell, Sarah