eval-n
($query as xs:string) as item()* external
See documentation of reflection:eval() except the main module that is to be executed may be nondeterministc. |
eval-s
($query as xs:string) as item()* external
See documentation of reflection:eval() except the main module that is to be executed may be sequential, i. |
eval-u
($query as xs:string) external
See documentation of reflection:eval() except the main module that is to be executed may be updating, i. |
eval
($query as xs:string) as item()* external
The purpose of this function is to (dynamically) execute an XQuery program from inside another XQuery program. |
invoke-n
($name as xs:QName) as item()* external
See documentation for reflection:invoke except the function that is to be invoked may be nondeterministic. |
invoke-s
($name as xs:QName) as item()* external
See documentation for reflection:invoke except the function that is to be invoked may be sequential, i. |
invoke-u
($name as xs:QName) external
See documentation for reflection:invoke-n except the function that is to be invoked may be updating, i. |
invoke
($name as xs:QName) as item()* external
The invoke function allows to dynamically call a function given its QName and parameters. |
declare %an:nondeterministic function reflection:eval-n($query as xs:string) as item()* external
declare %an:sequential function reflection:eval-s($query as xs:string) as item()* external
declare %an:nondeterministic function reflection:eval-u($query as xs:string) external
declare function reflection:eval($query as xs:string) as item()* external
The XQuery program that invokes the eval function will be referred to as the "outer" program and the XQuery program that is executed by the eval invocation will be referred to as the "inner" program. The function is given as a string argument. Typically, the outer program constructs this string dynamically, e.g., based on data extracted from documents and/or the values of external variables. The eval function treats this string as an XQuery main module. That is, it parses the string, compiles the resulting parse tree, executes the resulting execution plan, and finally returns the result or error (if any) to the outer program.
The given XQuery program needs to be a valid according to XQuery's MainModule production (see http://www.w3.org/TR/xquery/#doc-xquery-MainModule. Please note that the inner pogram must at least have the XQuery version of the outer program [err:XQST0031].
The inner program "inherits" the static and dynamic context of the outer program. Specifically, evaluation of the inner program is done in static and dynamic contextes that are initialized as copies of the static and dynamic contextes of the outer program at the place where the eval invocation appears at. This means that, for example, all variables that are in-scope at the place where the eval function is invoked from, are also in-scope inside the inner program and can be referenced there without having to be re-declared. On the other hand, declarations that appear in the prolog of the inner main module or are imported by the inner main module from library modules, hide their corresponding inherited declarations. For example, if the inner main module declares a variable or function with the same name as an inherited variable or function, the inner variable/function hides the inherited one.
If the inner program declares an external variable with the same name as an inherited variable, the value of the inherited variable is used to initialize the inner external variable. If, however, an inner external variable has no default initializer and no corresponding inherited variable, it will remain uninitialized, causing the inner program to raise an error when executed.
declare %an:nondeterministic %an:variadic function reflection:invoke-n($name as xs:QName) as item()* external
declare %an:variadic %an:sequential function reflection:invoke-s($name as xs:QName) as item()* external
declare %an:nondeterministic %an:variadic function reflection:invoke-u($name as xs:QName) external
declare %an:variadic function reflection:invoke($name as xs:QName) as item()* external
It is possible to invoke a function whose name is not known at compilation time -- it can be computed, passed through an external variable, taken from a file, etc. The first parameter must always be a QName identifying a known function.
The function is declared with the %an:variadic annotation. Hence, it allows
for an arbitrary number of parameters. All of these parameters (except the
first one) will be passed to the function that is called.
Example usage :
reflection:invoke ( xs:QName("fn:max"), (1,2,3) )
3.