One of the readers of my blog post ‘Oracle Service Bus 11g, Using Custom Xpath Functions asked we can reuse the custom xpath functions in a xsl transformation.
It’s possibel to reuse the jar and calll the custom functions from within a xsl transformation.
Starting with creating the resources needed for the custom xpath function :
- XML Configuration file (osb-custom.xml)
- Property file (optional, osb-custom.properties)
- Custom Function Class (jar package)
Restart the osb service so the new jar will get loaded.
– Create a new osb project
– Create a new xslt
[sourcecode language=”xml”]
[/sourcecode]
To be able to call a custom xpath function with the Xalan engine we need to add a new namespace_prefix + definition the the xsl
[sourcecode language=”xml”]
xmlns:cust=”xalan://tests.pipeline.CustomXQFunctions”
[/sourcecode]
– Start with xalan://
– Then the java package + classname, nl.xenta.osb.custom.functions.OsbUtils
– In the select of the value-of we eventually use the namespace-prefix + java method interface to call the java method, cust:customConcat($param1,$param2)
Create a new proxy service and use the xsl in for example an assing activity.
Deploy the service and use the testconsole to test it.
3 Responses to “Oracle Service Bus : Using custom xpath functions in xslt”
[…] http://www.xenta.nl/blog/2012/01/09/oracle-service-bus-using-custom-xpath-functions-in-xslt/ […]
Thanks Eric! This is really a life saver.
Just to share some of my experience regarding reusable xpath functions.
In WSO2 ESB http://wso2.com/products/enterprise-service-bus/ we can use java-script (script mediator) to define reusable funcions which enclose xpath functions or simple way is to make a reusable sequence which has the xpath logic in it.