saxon:query

Evaluates an XQuery query.

query($name as jt:net.sf.saxon.query.XQueryExpression?) ➔ item()*

Arguments

 

$name

jt:net.sf.saxon.query.XQueryExpression?

The compiled query to be evaluated

Result

item()*

query($name as jt:net.sf.saxon.query.XQueryExpression?, $context-item as item()?) ➔ item()*

Arguments

 

$name

jt:net.sf.saxon.query.XQueryExpression?

The compiled query to be evaluated

 

$context-item

item()?

The context item for the evaluation

Result

item()*

query($name as jt:net.sf.saxon.query.XQueryExpression?, $context-item as item()?, $params as node()*) ➔ item()*

Arguments

 

$name

jt:net.sf.saxon.query.XQueryExpression?

The compiled query to be evaluated

 

$context-item

item()?

The context item for the evaluation

 

$params

node()*

Parameters (external variables)

Result

item()*

Namespace

http://saxon.sf.net/

Notes on the Saxon implementation

Available since Saxon 9.1. The function is available both in XQuery and in XSLT.

Details

This function takes as input a compiled XQuery query, and runs the query, returning the result of evaluating the query. The first argument will generally be the result of calling the saxon:compile-query() extension function.

If the first argument is an empty sequence, the result is an empty sequence.

If only one argument is supplied, the context item for evaluating the query will be the same as the context item in the environment where the function is called, that is, the implicit second argument is ".". If there is no context item, however, no failure occurs unless the query attempts to reference the context item.

If the second argument is present it can be any item, which is used as the context item for the query. It can also be the empty sequence, in which case the query runs with no context item.

If the optional third argument is present, it is used to supply parameters (external variables) to the query. The value is a sequence of nodes. Each node must be an element node, attribute node, or document node; supplying a document node is equivalent to supplying all its element children. The name of the node must match an external variable name declared in the query prolog, and the atomized value of the node is used as the value of the parameter. If this is untypedAtomic then it is converted to the required type declared in the query.

The compiled stylesheet can be used repeatedly with different inputs.

Here is an example of how to use the function from XQuery:

declare namespace saxon = "http://saxon.sf.net/"; <out>{ let $q1 := "declare variable $x external; declare variable $y external; <z>{$x + $y + .}</z&>" return saxon:query(saxon:compile-query($q1), 4, (<x>3</x>, <y>2</y>)) }</out>

The result of the query is a sequence containing the single integer 9.

See also:

saxon:compile-query()