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

Missing From Home by Mary Burchell
HER BABY'S SECRET FATHER by LYNNE MARSHALL,
Platform by Michel Houellebecq
Wild River by P.J. Petersen
Diary of a Conjurer by D. L. Gardner
About Schmidt by Louis Begley