A conditional expression consists of a condition and two branch expressions. The condition must be a Boolean. If both branches have the same type, then the type of the conditional expression is also that type. Assume that $x and $y are both integers. Here is an example:
if ($x<$y) then 3 else 4 has type xs:integer
If the two branches have different types, then the type of the conditional expression is the union of those types. Here is an example:
if ($x<$y) then "three" else 4.00 has type (xs:string | xs:decimal)
Recall that in the XQuery formal type notation, a vertical bar indicates the union of two types. The union of a type with itself is just the type, so the rule about conditionals with two branches of the same type is ...