Logical operators

The expression E1 and E2 returns true if the effective boolean values of E1 and E2 are both true.

The expression E1 or E2 returns true if the effective boolean values of either or both of E1 and E2 are true.

The specification allows the operands to be evaluated in either order, but Saxon will normally evaluate them left-to-right, which means if you write something like $a instance of xs:integer and $x = (1 to $a), then you won't get an error if $a is not an integer. But the specification doesn't guarantee this.

Short-circuit boolean operators

The and and or operators now have stricter rules governing optimization. It is still permitted to evaluate the operands in either order, but an error in evaluating the right-hand operand must not be reported unless evaluation of that operand is actually necessary.

Saxon implements this rule as follows:

  • In the case of and, an error evaluating one operand is reported only if evaluation of the other operand returns true.

  • In the case of or, an error evaluating one operand is reported only if evaluation of the other operand returns false.

This means that the expression:

//chapter[pages=0 or length div pages]

will never fail with a divide-by-zero error, even if the operands are evaluated in a different order.

A similar rule is adopted for expressions with multiple predicates, for example the following is now guaranteed to return no failure if @code is non-numeric:

@code[. castable as xs:integer][xs:integer(.) = 2]