>
> Michael, I wonder if your worries about preventing optimization are not taken care of by the approach BaseX takes. To recapitulate: the BaseX approach is to supply *explicit* bindings to external variables declared within the expression; the bindings are passed in via a map argument providing the name/value pairs. Example:
>
> let $x := 1 return
> xquery:eval('declare variable $y external; $y + 1', map{'y': $x})
>
Ah, right, I missed that. That is of course essentially what saxon:evaluate does except that it predates maps, so you can only bind to one of the fixed names $p1 to $p9. Plus we're dealing with XPath rather than XQuery so there's no declaration:
saxon:evaluate("$p1 + 1", $x)
Michael Kay
Saxonica