Converting the result of a Java extension function

The result of a Java extension function is converted to an XDM value (a value suitable for use in XPath expressions) using the general conversion rules described at Converting Java values to XDM values.

The following additional rules apply specifically to the handling of the return value from Java methods and constructors used as extension functions:

  • In the case of a method returning void, then:

    • If the option ?void=this was present in the namespace URI of the function name, and the method is an instance-level (non-static) method, then the return value is the value of the first argument, that is, the Java object to which the method was applied, wrapped as an external Java object. (This option can help to make execution of extensions with side-effects more predictable, by explicit chaining of such methods in the XPath code.)
    • Otherwise, the return value is an empty sequence.
  • If the Java value is null, the XPath value is an empty sequence.

  • When calling a constructor, the resulting XPath value is not converted; it will always be of type "wrapped Java object". The only way of using this result is by passing it to another external function, or by converting it to one of the standard XPath data types as described above.

    Note that calling will result in a wrapped ArrayList object. By constrast, calling a method that returns an ArrayList will result in an XPath sequence whose items are constructed by converting the members of the returned ArrayList.

    It is also possible to force the result of a method to be returned as a wrapped Java object by making the function call in the initializer of a variable with an appropriate type declaration: for example: <xsl:variable name="x" select="..." as="Q{}java.util.List causes a returned java.util.List to be returned as a wrapped Java object, rather than being converted to an XDM sequence.