SAXONICA

Saxon Documentation
Full Contents
About Saxon
Changes in this Release
Notices
Using XSLT 2.0
Using XQuery
| Introduction
| Running XQuery from the Command Line
| Running Queries from a Java Application
| Using XQuery Update
| Calling XQuery Functions from Java
| Result Format
» | Compiling Queries to Java code
| Extensibility
| Extensions
| Use Cases
Handling Source Documents
XML Schema Processing
XPath API for Java
Saxon on .NET
Extensibility
Saxon Extensions
Sample Saxon Applications
The Saxon SQL Extension
XSLT Elements
XPath 2.0 Expression Syntax
Function Library
Standards Conformance

# Calling Compiled Queries from an Application

This section does not apply to code generated with the `-servlet` option.

When a query is compiled, as well as having a `main` method allowing invocation from the operating system command line, it will also have a `run()` method allowing invocation from a Java application. This takes two parameters: a JAXP `Result` object to define the destination of the query output, and an `outputProperties` value to define serialization properties.

A query compiled in this way is not thread-safe. A new instance of the generated class should be created in each thread. Within a thread, the object is serially reusable.

Parameters to the query may be supplied using the method `setExternalVariable`. This accepts the name of the variable in Clark notation ({uri}local), and the value as an instance of Saxon's `ValueRepresentation` class. Most commonly this will be a `StringValue`, an `Int64Value`, or a `BooleanValue`.

Next