# Extension functions

This section describes extension functions built in to the Saxon product. For information on writing your own extension functions, see Writing extension functions (Java) or Writing extension functions (.NET)

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:column-number(node): gets the column number of a node in the source document

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

- 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:file-last-modified(): determines when a file was last modified

- 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:generate-id(): generates a unique ASCII identifier for a node

- 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:in-summer-time(): tests whether a given date/time is in summer time (daylight savings time)

- saxon:is-whole-number(): tests whether a given value has no fractional part

- saxon:item-at(): selects the item at a given position in a sequence

- saxon:last-modified(): determines when the XML file from which a node was loaded was last modified

- saxon:leading(): returns items in a sequence up to the first one matching 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:namespace-node(): creates a namespace node

- saxon:stream(): evaluates an expression in streaming mode

- 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 a node

- saxon:print-stack(): returns a formatted string representing the current execution stack

- saxon:query(): Runs an XSLT transformation

- saxon:result-document(): constructs a document and serializes it, writing the result to a file in filestore

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

- saxon:sort(): sorts a sequence of nodes or atomic values

- 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: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 or atomic value

- saxon:unparsed-entities(): returns a list of the unparsed entities declared within a document

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