Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Note that both branches (thethen
and the
else
) must be present. It's quite common to write
else
()to return nothing (an empty sequence) when the condition is
false
, but you have to write this explicitly.
The expression used as the condition to be tested (inside the parentheses) is evaluated to give its
effective boolean value
. Unusually, XPath 2.0 doesn't apply strict type checking to this expression, rather it defines a set of rules allowing a wide range of values to be converted to the
xs:boolean
values
true
or
false
. The rules are the same as for the
boolean()
function described on page 721, in summary:
There is no atomization applied to any nodes in the sequence. This means that if the value includes one or more nodes, the result is
true
, regardless of the contents of the node. Even if@married
is an attribute whose typed value is the
xs:boolean
value false, the result of the expressionif (@married) then
“yes“ else “no”is the string
yes
. If you want to test the contents of the node, rather than testing for its existence, use the
data()
function to atomize it explicitly, or write the test in the formif
(@married
=
true())
then
...