http://www.zorba-xquery.com/modules/reflection ZC

Module Description
Before using any of the functions below please remember to import the module namespace:
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.

Author:

Nicolae Brinza

XQuery version and encoding for this module:

xquery version "3.0" encoding "utf-8";

Zorba version for this module:

The latest version of this module is 2.0. For more information about module versioning in Zorba please check out this resource.

Module Resources
Namespaces
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
Function Summary
External eval ( $query as xs:string ) as item()*
The purpose of this function is to (dynamically) execute an XQuery program from inside another XQuery program.
Nondeterministic External 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.
Sequential External 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.
Updating Nondeterministic External 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.
Variadic External invoke ( $name as xs:QName ) as item()*
The invoke function allows to dynamically call a function given its QName and parameters.
Updating Nondeterministic Variadic External invoke-n ( $name as xs:QName ) as item()*
See documentation for reflection:invoke except the function that is to be invoked may be nondeterministic.
Sequential Variadic External 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.
Updating Nondeterministic Variadic External 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.
Functions
External eval back to 'Function Summary'
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.

Parameters:
Returns:
Errors:
Examples:

Nondeterministic External eval-n back to 'Function Summary'
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.

Parameters:
Returns:
Errors:

Sequential External eval-s back to 'Function Summary'
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.

Parameters:
Returns:
Errors:
See:

Updating Nondeterministic External eval-u back to 'Function Summary'
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.

Parameters:
Returns:
Errors:
See:

Variadic External invoke back to 'Function Summary'
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 
.

Parameters:
Returns:
Errors:
Examples:

Updating Nondeterministic Variadic External invoke-n back to 'Function Summary'
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.

Parameters:
Returns:
Errors:
See:

Sequential Variadic External invoke-s back to 'Function Summary'
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.

Parameters:
Returns:
Errors:
See:

Updating Nondeterministic Variadic External invoke-u back to 'Function Summary'
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.

Parameters:
Returns:
Errors:
See:

blog comments powered by Disqus