SAXONICA

Saxon Documentation
Full Contents
About Saxon
Changes in this Release
Notices
Using XSLT 2.0
Using XQuery
Handling Source Documents
XML Schema Processing
XPath API for Java
Saxon on .NET
Extensibility
Saxon Extensions
| Introduction
| EXSLT Extensions
| Extension attributes (XSLT only)
| Additional serialization parameters
» | Extension functions
| Extension instructions
Sample Saxon Applications
The Saxon SQL Extension
XSLT Elements
XPath 2.0 Expression Syntax
Function Library
Standards Conformance

# saxon:query()

saxon:query($query as jt:net.sf.saxon.query.XQueryExpression?) ==> item()*

saxon:query($query as jt:net.sf.saxon.query.XQueryExpression?, $contextItem as item()?) ==> item()*

saxon:query($query as jt:net.sf.saxon.query.XQueryExpression?, $contextItem as item()?, $params as node()*) ==> item()*

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 function is available both in XQuery and in XSLT.

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/";
    declare namespace xsl = "http://www.w3.org/1999/XSL/Transform";

    <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.

Next