Calling JAXP XPath extension functions
The JAXP XPath interface includes an interface
FunctionResolver which can
be used to bind a function call appearing in the XPath expression to a user-written Java
implementation of the interface
java.xml.xpath.XPathFunction. The form in
which parameters are passed to such a function, and the form in which it returns its
results, are not precisely defined in the JAXP specification, so this section fills the
gap. Note that the calling conventions are likely to differ from those used by other
The extension function is called by invoking the method
XPathFunction.evaluate(), which takes a list of arguments, and returns
the function result.
The arguments are therefore supplied as a list. Each item in this list represents one argument. The argument value is represented as follows:
If the value of the argument is a singleton item, it will be passed as the "natural Java equivalent" of the item's type. For example, a double will be passed as an instance of
java.lang.Double, a string as an instance of
java.lang.String. An untyped atomic value is treated as a string. An
xs:integer(even if it belongs to a subtype such as
xs:short) is converted to a
java.lang.BigInteger. The more specialized XML Schema primitive types such as
xs:durationare passed in their native Saxon representation (a subclass of net.sf.saxon.value.AtomicValue). A node will be passed as an instance of net.sf.saxon.NodeInfo, unless it wraps a foreign node (e.g. a DOM or JDOM node) in which case the foreign node is passed.
If the value is a sequence of any length other than one (including zero), then the value that is passed is a
List, where each item in the list is converted as described in rule (1).
If the return value conforms to the above conventions, then it will be accepted. However
Saxon will also accept a wide range of other return values, including of course a
List containing one item.