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

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

It is easy to forget this when testing attribute values; for example, the following two examples behave the same way if the attribute
go
is present (they output
go
if the value is anything other than
no
), but they behave differently if the attribute is absent (the second one outputs
go
, but the first one outputs nothing).

1: if (@go!=‘no’) then “go” else “”

2: if (not(@go=‘no’)) then “go” else “”

When used with sequences, the comparison operators such as
=
and
!=
are subject to an implicit
if there exists
qualifier:
$X=$Y
is true
if there exists an item
x
in
$X
and an item
y
in
$Y
such that
x
eq
y
. If you want to achieve an
if all
qualifier, for example,
if all nodes in
$N
have a
size
attribute equal to 0
, then you can achieve this by negating both the condition and the expression as a whole:
not($N/@size!=0)
. But in XPath 2.0, it is probably clearer to write this out explicitly:

Other books

The Becoming Trilogy Box Set (Books 1-3) by Raven, Jess, Black, Paula
Private Deceptions by Glenn, Roy
A Highland Duchess by Karen Ranney
How to Cook a Moose by Kate Christensen
Pórtico by Frederik Pohl
Ramage At Trafalgar by Dudley Pope
Sharpshooter by Cynthia Eden
Extra Innings by Tiki Barber, Ronde Barber and Paul Mantell