The util module
Introduction
The util module (function namespace
util:eval()
- util:eval()
-
This function is used to dynamically execute a constructed XQuery expression inside a running XQuery script. This can be very handy in some cases - for example, web-based applications that dynamically generate queries based on HTTP request parameters the user has passed.
By default, the dynamically executed query inherits most of the current context, including local variables:
let $a := "Hello" return util:eval("$a")
Consider the following simple example script in which any two numbers submitted by a user are added or subtracted:
In this example, there is one XQuery script responsible for evaluating the user-supplied parameters, which uses the parameters from the HTTP request to construct another XQuery expression, which it then passes to util:eval for evaluation. The application would then post-process the returned results, and display them to the user. (For more information on how to write web applications using XQuery, go to our Developer's Guide.)