# 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:call(): calls a first-class function previously created using saxon:function()

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

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

- saxon:distinct(): eliminates duplicate values from a set of nodes

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

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

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

- 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:highest(): finds the nodes having the highest value for some expression

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

- saxon:line-number(): gets the line number of the current 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-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: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

Expand | Next