I'm confused with the below query, I expect the result should be 5 but it returns an empty sequence.
let $num := 5
let $num1 := ()
let $add := $num + $num1
return $add
I don't know how close Marklogic XQuery is to the W3C XQuery standard but in that standard the rules for arithmetic expressions https://www.w3.org/TR/2010/REC-xquery-20101214/#id-arithmetic clearly say
The first step in evaluating an arithmetic expression is to evaluate its operands. The order in which the operands are evaluated is implementation-dependent.
Each operand is evaluated by applying the following steps, in order:
Atomization is applied to the operand. The result of this operation is called the atomized operand.
If the atomized operand is an empty sequence, the result of the arithmetic expression is an empty sequence
So the empty sequence is the defined result as one operand is the empty sequence.
Perhaps the sum()
function, let $add := sum(($num, $num1))
, is more what you are looking for.