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
The XPath API
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

# Extension functions

A Saxon extension function is invoked using a name such as `saxon:localname()`.

The `saxon` prefix (or whatever prefix you choose to use) must be associated with the Saxon namespace URI `http://saxon.sf.net/`.

For example, to invoke the `saxon:evaluate()` function in XSLT, write:

    <xsl:variable name="expression"
          select="concat('child::', $param, '[', $index, ']')"/>
    ..
    <xsl:copy-of select="saxon:evaluate($expression)"
         xmlns:saxon="http://saxon.sf.net/"/>

The equivalent in XQuery is:

    declare namespace saxon="http://saxon.sf.net/";
    declare variable $param as xs:string external;
    declare variable $index as xs:integer external;
    declare variable $expression :=
          concat('child::', $param, '[', $index, ']');
    saxon:evaluate($expression)

The extension functions supplied with the Saxon product are as follows:

- saxon:analyze-string(): analyzes a string using a regular expression

- saxon:base64Binary-to-octets(): converts an xs:base64Binary value to a sequence of octets

- saxon:base64Binary-to-string(): converts an xs:base64Binary value to a string, given its encoding

- saxon:call(): calls a first-class function previously created using saxon:function()

- saxon:compile-stylesheet(): compiles a stylesheet that can subsequently be used as input to saxon:transform()

- saxon:decimal-divide(): performs decimal division with user-specified precision

- saxon:deep-equal(): compares two sequences for deep equality

- saxon:discard-document(): marks a document as being eligible for garbage collection

- saxon:eval(): evaluates a stored expression created using saxon:expression

- saxon:evaluate(): evaluates an XPath expression supplied dynamically as a string

- saxon:evaluate-node(): evaluates an XPath expression held in a node of a source document

- saxon:expression(): creates a stored expression for subsequent evaluation using saxon:eval()

- saxon:find(): finds items that match a given key value within an indexed sequence

- saxon:for-each-group(): groups a set of items on the basis of a grouping key

- saxon:format-dateTime(): formats a date, time, or dateTime value

- saxon:format-number(): formats a number for output

- saxon:function(): creates a first-class function that can be passed as an argument to other functions

- saxon:get-pseudo-attribute(): parses the content of a processing instruction

- saxon:has-same-nodes(): tests whether two sequences contain the same nodes

- saxon:hexBinary-to-octets(): converts an xs:hexBinary value to a sequence of octets

- saxon:hexBinary-to-string(): converts an xs:hexBinary value to a string, given its encoding

- saxon:highest(): finds the nodes having the highest value for some expression

- saxon:index(): creates an indexed sequence, allowing efficient retrieval using a key value

- saxon:leading(): finds the values in a sequence up to the first one that doesn't match a condition

- saxon:line-number(node): gets the line number of a node in the source document

- saxon:lowest(): finds the nodes having the lowest value for some expression

- saxon:max(): finds the maximum value of a set of nodes

- saxon:min(): finds the minimum value of a set of nodes

- saxon:namespace-node(): creates a namespace node

- saxon:octets-to-base64Binary(): converts a sequence of octets to an xs:base64Binary value

- saxon:octets-to-hexBinary(): converts a sequence of octets to an xs:hexBinary value

- saxon:parse(): parses an XML document supplied as a string

- saxon:path(): returns an XPath expression that identifies the context node

- saxon:serialize(): returns the XML representation of a document or element, as a string

- saxon:string-to-base64Binary(): encodes a string to an xs:base64Binary value, using a given encoding

- saxon:string-to-hexBinary(): encodes a string to an xs:hexBinary value, using a given encoding

- saxon:string-to-utf8(): returns the UTF8 representation of a string

- saxon:sum(): sums the result of computing an expression for every node in a sequence

- saxon:system-id(): returns the system ID of the document containing the context node

- saxon:transform(): Runs an XSLT transformation

- saxon:try(): allows recovery from dynamic errors

- saxon:type-annotation(): returns the type annotation of a node

The Java source code of these functions (which in most cases is extremely simple), can be used as an example for writing other user extension functions. It is found in class `net.sf.saxon.functions.Extensions`. Source code is available in the download of Saxon-B from SourceForge

Next