For every pair of arguments, the function calculates values of these arguments and then creates a new temporary local variable whose name is the string value of the first argument in pair and the value assigned is the value of the second argument in pair. Obviously, the argument for variable name is usually a constant string of alphanumeric characters. The expression for a value of variable number I may refer to variables created during steps 1 to I-1. When all pairs of arguments are turned into temporary variables, the last argument is calculated and its value is returned as the value of the whole expression.
Temporary variables are destroyed on return.
This function is used in the implementation of "LET" control operator in XQUERY, so you will probably use that operator in XQUERY expressions, not the function. This function may be useful in XPATH expressions and in XSLT stylesheets. It is not a part of library of standard XQUERY 1.0 functions.
Any, depending on the type of retval expression.
These two expressions are equivalent, but first may be used in any XPATH while second is written in XQUERY syntax
let('baseprice', /item/price, 'discount', 0.20, $baseprice * (1.0 - $discount)) LET $baseprice := /item/price, $discount := 0.20 RETURN $baseprice * (1.0 - $discount)