saxon:xquery

Compiles an XQuery query, delivering a function item that can be called to execute the query.

xquery($query as xs:string) ➔ function(item()?, map(xs:QName, item()*) as item()*

Arguments

 

$query

xs:string

The query to be evaluated

Result

function(item()?, map(xs:QName, item()*) as item()*

Namespace

http://saxon.sf.net/

Saxon availability

Requires Saxon-PE or Saxon-EE. Implemented since Saxon 11.

Notes on the Saxon implementation

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

Details

This function takes as input an XQuery query, and returns a function item, which can be evaluated to run the query.

The returned function takes two arguments:

  1. The context item for execution of the query. The argument may be set to an empty sequence if no context item is required.
  2. A map containing values of parameters (external variables) for the query. The keys are xs:QNames representing the parameter names; the corresponding values are arbitrary values for the parameters.

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>" let $qry := saxon:xquery($q1) return $qry(4, map{xs:QName('x'): 3, xs:QName('y'): 2}) }</out>

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

See also:

saxon:compile-query()

saxon:query()