ODE uses the Saxon XPath processor to support custom XPath functions.
This text is a quick summary of Saxon's own extensibility documentation. I recommend you read it if you need more information. It goes into much more detail on Java invocation, supported data types, conversions, etc.
To use XPath extensions, you must use the XPath 2.0 expression language.
An extension function is invoked using a name such as prefix:localname()
. The prefix must be the prefix associated with a namespace declaration that is in scope.
Extension functions must be implemented in Java. You bind external Java classes by encoding the class name part in the namespace URI. The URI for the namespace identifies the class where the external function will be found. The namespace URI must be java:
followed by the fully-qualified class name; for example xmlns:date="java:java.util.Date"
). The class must be on the classpath, or more specifically accessible from the current classloader.
xmlns:date="http://www.jclark.com/xt/java/java.util.Date"
). This approach is no longer supported in Saxon 9.x and you should now use the java:
prefix.
<assign> <copy xmlns:ext="java:com.example.xpath.Random"> <from expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0">ext:random()</from> <to>$myVariable</to> </copy> </assign> :::java package com.example.xpath; /** * Returns a random number */ public class Random { public static int random() { java.util.Random randomizer = new java.util.Random(); int number = randomizer.nextInt(); return Math.abs(number); } }
You can download source code or the ready-to-use jar for testing.
There are a few options: