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.76Mb size Format: txt, pdf, ePub
ads

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.

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

Other books

Dead in the Dog by Bernard Knight
Moonlighting in Vermont by George, Kate
The Girl Who Drank the Moon by Kelly Barnhill
Pan's Realm by Christopher Pike
Showdown With Fear by Stephen Wade
Babylon South by Jon Cleary
The Fresco by Sheri S. Tepper
The Masked City by Genevieve Cogman