You should be able to call instance methods of the "external object" passed as a parameter in the form that you describe. If $ object is such an object, and com.package.MyClass is its class, and you want to call the getColor method for this object, then
(a) you need to declare a namespace such as xmlns: Myclass = "java: com.package.MyClass"
(b) you call the method as MyClass: getColor ($ object)
This Java calling mechanism is referred to in Saxon as “reflective extension functions”. It is not supported in Saxon Home Edition. You will need either the Saxon Professional Edition or the old open source Saxon-B product. Another mechanism in Saxon-HE is called "integrated extension functions", but it takes a bit more coding on the Java side to declare argument and result types.
You need to know that with the help of reflective extension functions, Saxon does its best to map Java types to XPath types and does not always do the mapping as you would like, especially when using the types collection.
Try to avoid using methods with side effects, such as customization methods. There is no absolutely reliable way to ensure in Saxon that such calls are made in any particular order, and sometimes the Saxon optimizer will find a way to organize a request that avoids making a call at all. If you must make such calls, process them as if the call returned a result (for example, an empty sequence) and used the call so that when the result was returned, the result would appear in your style sheet output.
source share