Converting the Result of an Extension Function

This section explains how the value returned by a Java extension function is converted to an XPath value. The same rules are used in converting a Java object supplied as a parameter to a stylesheet or query.

The result type of the method is converted to an XPath value as follows.

Note that Saxon's two principal tree structures both conform to the DOM Core Level 2 interface. However, they are read-only: any attempt to modify the tree causes an exception. Saxon's trees can only be built using the Saxon subclasses of the net.sf.saxon.tree.Builder class, and they cannot be modified in situ. (The simplest way for a Java application to build a Saxon tree is by using the net.sf.saxon.xpath.XPathEvaluator class.)

In XSLT, the system function function-available(String name) returns true if there appears to be a method available with the right name. The function also has an optional second argument to test whether there is a method with the appropriate number of arguments. However, it is not possible to test whether the arguments are of appropriate types. If the function name is "new" it returns true so long as the class is not an abstract class or interface, and so long as it has at least one constructor.

There are a number of extension functions supplied with the Saxon product: for details, see extensions.html. The source code of these methods, 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.

Expand

Next