I wonder if it's possible to create a query like when using Saxon 9.9HE (addressed by baseX):
let $where := '$x//element[text() = "content"]'
for $x in db:open("my_db")//something
where $where
return $x//something_else
In my application, the where-clause is built externaly (PHP) based on some conditions and I simply want to pass that to the xquery script so that I can use one base script for all queries, each of which differing in the passed-by where-clause only. Other variables can be passed easily to the script since they contain no path expressions but just skalars.
Is it possible to have an expression in a variable?
I had some tries with xquery:eval() and xquery:parse() (both baseX functions), without success however. The errors mostly are unknown variable $x , context is undeclared , or expecting return
If no error occurs, I get ALL elements since the where-clause seems to evaluate to true, thus returning simply everything
My current workaround is to read the xquery script, replace the $where, and execute it then. Is there a nice way to do it in xquery alone?
xquery:evalorxquery:parsefunctions. - Martin Honnen