Introduction:
The extension function mechanism allows the users of XSL processor to call any Java method from XSL expressions. Java extension functions should belong to the namespace that starts with http://www.oracle.com/XSL/Transform/java/. An extension function that belongs to the namespace http://www.oracle.com/XSL/Transform/java/classname, refers to methods in the class classname. Eg: The namespace http://www.oracle.com/XSL/Transform/java/java.lang.String can be used to call java.lang.String methods from XSL expressions.

Static Vs Non-static method:
If the method is a non-static method of the class, then the first parameter will be used as the instance on which the method is invoked, and the rest of the parameters are passed on to the method. If the extension function is a static method, then all the parameters of the extension function are passed on as parameters to the static function.

Example: Static function
<xsl:stylesheet xmlns:math="http://www.oracle.com/XSL/Transform/java/java.lang.Math">
<xsl:template match="/">
<xsl:value-of select="math:ceil('12.34')"/>
</xsl:template>
</xsl:stylesheet>

will print out '13'.

Constructor:
The extension function 'new' creates a new instance of the class (acts as the constructor).

Example:
<xsl:stylesheet  xmlns:jstring="http://www.oracle.com/XSL/Transform/java/java.lang.String">
<xsl:template match="/">
<!-- creates a new java.lang.String and stores it in the variable str1 -->
<xsl:variable name="str1" select="jstring:new('Hello World')"/>
<xsl:value-of select="jstring:toUpperCase($str1)"/>
</xsl:template>
</xsl:stylesheet>

will print out 'HELLO WORLD'.

Return Value:
The result of an extension function can be of any type (including the five types defined in XSL : NodeList, boolean, String, Number, and resulttree), and can be stored in variables or passed on to other extension functions. If the result is of one of the five types defined in XSL, then the result can be returned as the result of an XSL expression.

Example:
<!-- Declare extension function namespace -->
<xsl:stylesheet xmlns:parser = "http://www.oracle.com/XSL/Transform/java/oracle.xml.parser.v2.DOMParser" xmlns:document = "http://www.oracle.com/XSL/Transform/java/oracle.xml.parser.v2.XMLDocument" >

<xsl:template match ="/">
<!-- Create a new instance of the parser, store it in myparser variable -->
<xsl:variable name="myparser" select="parser:new()"/>
<!-- Call a non-static method of DOMParser. Since the method is anon-static method, the first parameter is the instance on which themethod is called. This is equivalent to $myparser.parse('test.xml') -->
<xsl:value-of select="parser:parse($myparser, 'test.xml')"/>
<!-- Get the document node of the XML Dom tree -->
<xsl:variable name="mydocument" select="parser:getDocument($myparser)"/>
<!-- Invoke getelementsbytagname on mydocument -->
<xsl:for-each select="document:getElementsByTagName($mydocument,'elementname')">
......
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Datatypes:
Overloading based on number of parameters and type is supported. Implicit type conversion is done between the five XSL types as defined in XSL. Type conversion is done implicitly between (String, Number, Boolean, ResultTree) and from NodeSet to (String, Number, Boolean, ResultTree). Overloading based on two types which can be implicitly converted to each other is not permitted.

Eg: The following overloading will result in an error in XSL, since String and Number can be implicitly converted to each other.

abc(int i){}

abc(String s){}

Mapping between XSL type and Java type is done as following:
String -> java.lang.String
Number -> int, float, double.
Boolean -> boolean
NodeSet -> XMLNodeList
ResultTree -> XMLDocumentFragment.