- All Modules
- All Functions
-
www.w3.org
- 2005
- XDM
- store
- introspection
- reflection
- external
-
xqdoc
-
xqdoc
(E)
-
project_xqdoc
- xqdoc2xhtml
-
xqdoc
(E)
- data processing
- expath.org
- www.functx.com
- Zorba
- debugger
- error
- jsoniq.org
- www.zorba-xquery.com
http://www.zorba-xquery.com/modules/reflection
import module namespace reflection = "http://www.zorba-xquery.com/modules/reflection";
This module provides functions to dynamically invoke functions or main modules, respectively. Each of the functions (invoke or eval) come in four variants depending whether the expression being invoked is simple, nondeterministic, updating, or sequential.
Nicolae Brinza
xquery version "3.0" encoding "utf-8";
The latest version of this module is 2.0. For more information about module versioning in Zorba please check out this resource.
- the XQuery module can be found here.
an | http://www.zorba-xquery.com/annotations |
err | http://www.w3.org/2005/xqt-errors |
reflection | http://www.zorba-xquery.com/modules/reflection |
ver | http://www.zorba-xquery.com/options/versioning |
![]() |
eval
(
$query as xs:string
) as item()* The purpose of this function is to (dynamically) execute an XQuery program from inside another XQuery program. |
![]() ![]() |
eval-n
(
$query as xs:string
) as item()* 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()* See documentation of reflection:eval() except the main module that is to be executed may be sequential, i. |
![]() ![]() ![]() |
eval-u
(
$query as xs:string
) as See documentation of reflection:eval() except the main module that is to be executed may be updating, i. |
![]() ![]() |
invoke
(
$name as xs:QName
) as item()* The invoke function allows to dynamically call a function given its QName and parameters. |
![]() ![]() ![]() ![]() |
invoke-n
(
$name as xs:QName
) as item()* See documentation for reflection:invoke except the function that is to be invoked may be nondeterministic. |
![]() ![]() ![]() |
invoke-s
(
$name as xs:QName
) as item()* See documentation for reflection:invoke except the function that is to be invoked may be sequential, i. |
![]() ![]() ![]() ![]() |
invoke-u
(
$name as xs:QName
) as See documentation for reflection:invoke-n except the function that is to be invoked may be updating, i. |
declare function reflection:eval ( $query as xs:string ) as item()*
The purpose of this function is to (dynamically) execute an XQuery program from inside another XQuery program. 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.
- $query the query string to be evaluated
- the result of evaluating the query
- whatever error the evaluated XQuery may return.
- err:XQST0031 If the XQuery version of the inner program is greater than the version of the outer program.
declare function reflection:eval-n ( $query as xs:string ) as item()*
See documentation of reflection:eval() except the main module that is to be executed may be nondeterministc.
- $query the query string to be evaluated
- the result of evaluating the query
- whatever error the evaluated XQuery may return
- err:XQST0031 If the XQuery version of the inner program is greater than the version of the outer program.
declare function reflection:eval-s ( $query as xs:string ) as item()*
See documentation of reflection:eval() except the main module that is to be executed may be sequential, i.e. may have side-effects.
- $query the query string to be evaluated
- the result of evaluating the query (the result is not supposed to contain any PUL).
- whatever error the evaluated XQuery may return
- err:XQST0031 If the XQuery version of the inner program is greater than the version of the outer program.
- reflection:eval()
declare function reflection:eval-u ( $query as xs:string ) as
See documentation of reflection:eval() except the main module that is to be executed may be updating, i.e. return a pending update list.
- $query the query string to be evaluated
- the PUL resulting from evaluating the query
- whatever error the evaluated XQuery may return
- err:XQST0031 If the XQuery version of the inner program is greater than the version of the outer program.
- reflection:eval()
declare function reflection:invoke ( $name as xs:QName ) as item()*
The invoke function allows to dynamically call a function given its QName
and parameters. 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) )
Returns
3.
- $name the QName of the function that is to be invoked
- the result that is returned by the invoked function
- whatever error the invoked function may return
declare function reflection:invoke-n ( $name as xs:QName ) as item()*
See documentation for reflection:invoke except the function that is to be invoked may be nondeterministic.
- $name the QName of the function that is to be invoked
- the result that is returned by the invoked function
- whatever error the invoked function may return
- reflection:invoke()
declare function reflection:invoke-s ( $name as xs:QName ) as item()*
See documentation for reflection:invoke except the function that is to be invoked may be sequential, i.e. may have side-effects.
- $name the QName of the function that is to be invoked
- the result that is returned by the invoked function
- whatever error the invoked function may return
- reflection:invoke()
declare function reflection:invoke-u ( $name as xs:QName ) as
See documentation for reflection:invoke-n except the function that is to be invoked may be updating, i.e. return a pending update list.
- $name the QName of the function that is to be invoked
- the result that is returned by the invoked function
- whatever error the invoked function may return
- reflection:invoke-n()