SAXONICA

Saxon Documentation
Full Contents
About Saxon
Changes in this Release
Conditions of Use
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:expression()

saxon:expression($expr as xs:string) ==> jt:net.sf.saxon.functions.Evaluate-PreparedExpression

This function creates a stored expression that can be evaluated repeatedly with different argument values and a different dynamic context.

The supplied string must contain an XPath expression. The result of the function is a stored expression, which may be supplied as an argument to other extension functions such as saxon:eval, saxon:sum and saxon:distinct. The result of the expression will usually depend on the current node. The context for the expression includes the namespaces in scope at this point in the stylesheet. The expression may contain references to the nine variables `$p1`, `$p2`, ... `$p9` only. It may contain calls on Java extension functions, including Saxon and EXSLT-defined functions (other than those which are restricted to use within stylesheets, for example the saxon:evaluate() function itself). But it does not allow access to stylesheet variables, stylesheet functions, or functions defined in the XSLT specification such as `key()` or `format-number()`. If the expression contains namespace prefixes, these are interpreted in terms of the namespace declarations in scope at the point where the `saxon:expression()` function is called, not those in scope where the stored expression is evaluated.

The stored expression (if it is to be evaluated using `saxon:eval()`) may contain references to variables named `$p1`, `$p2`, ... `$p9`. The values of these variables can be supplied when the expression is evaluated using `saxon:eval`. The second argument of `saxon:eval` supplies the value of `$p1`, the third argument supplies the value of `$p2`, and so on.

For example, following `<xsl:variable name="add" select="saxon:expression('$p1 + $p2')"/>`, the instruction `<xsl:value-of select="saxon:eval($add, 6, 7)"/>` will output `13`.

Next