Short-circuit boolean operators

Saxon 11 implemented two additional boolean operators: orElse and andAlso. These are retained in Saxon 12, but they are likely to be dropped as the community group has taken a different direction.

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:

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]