ServiceMix Saxon
The ServiceMix Saxon component is a standard JBI Service Engine for XSLT / XQuery. This component is based on Saxon and supports XSLT 2.0 and XPath 2.0, and XQuery 1.0.
Use of result property
Due to a bug in the latest release of Saxon, the dom
value of the result
attribute causes exceptions to be thrown. Hence, the default value has been changed to string
to avoid problems. This bug only affects the XSLT endpoint, so feel free to use the dom
value for XQuery endpoints.
Maven Archetype
You can use Maven servicemix-saxon-service-unit archetype to create a Saxon service unit:
mvn archetype:create \ -DarchetypeGroupId=org.apache.servicemix.tooling \ -DarchetypeArtifactId=servicemix-saxon-service-unit \ -DarchetypeVersion=2010.01 \ -DgroupId=your.group.id \ -DartifactId=your.artifact.id \ -Dversion=your-version
Endpoints Configuration
XSLT Endpoint
The XSLT endpoint can be used to apply an XSLT stylesheet to the incoming exchange and will return the transformed result as the output message.
Simple transformation:
<saxon:xslt service="test:xslt" endpoint="endpoint" resource="classpath:transform.xsl" />
Dynamic stylesheet selection:
<saxon:xslt service="test:xslt-dynamic" endpoint="endpoint"> <saxon:expression> <bean class="org.apache.servicemix.expression.PropertyExpression"> <property name="property" value="xslt.source" /> </bean> </saxon:expression> </saxon:xslt>
Endpoint attributes
Name |
Type |
Description |
Required |
---|---|---|---|
resource |
the spring resource pointing to the XSLT stylesheet |
one of (resource, expression) |
|
expression |
expression used to dynamically load the stylesheet |
one of (resource, expression) |
|
wsdlResource |
if set, the wsdl will be retrieved from the given Spring resource |
no |
|
transformerFactory |
TransformerFactory |
TraX factory to create transformers |
defaults to Saxon implementation |
configuration |
Saxon configuration |
no |
|
result |
String |
Output result type |
defaults to |
copyAttachments |
boolean |
|
defaults to |
copyProperties |
boolean |
|
defaults to |
copySubject |
boolean |
|
defaults to |
useDomSourceForXslt |
boolean |
force the transformation of the xslt stylesheet into a DOM document before giving it to the transformer |
defaults to |
useDomSourceForContent |
boolean |
force the transformation of the incoming JBI message into a DOM document before giving it to the transformer |
no |
parameters |
Map |
additional parameters to give to the transformation engine |
no |
Using properties and parameters
All properties defined on the JBI exchange and input JBI message will be available for use inside the XSLT stylesheet as parameters.
In addtion to those properties and the one specified in the parameters
property on the endpoint, the following objects are also available:
- exchange: the JBI exchange
- in: the input JBI NormalizedMessage
- component: the XsltEndpoint instance being called
All those parameters can be accessed using XSLT standard ways.
For example:
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'> <xsl:param name="stringParam"/> <xsl:param name="integerParam"/> ... </xsl:stylesheet>
and the configuration of those values on the endpoint (in case they are not available on the JBI exchange / message):
<saxon:xslt service="test:xslt-params" endpoint="endpoint" resource="classpath:parameter-test.xsl"> <property name="parameters"> <map> <entry key="stringParam" value="cheeseyCheese"/> <entry key="integerParam"> <bean class="java.lang.Integer"> <constructor-arg index="0" value="4002"/> </bean> </entry> </map> </property> </saxon:xslt>
XSLT Proxy
One common use case is the need to transform a request coming from a service and send it to another service and do the same with the response. A simple example is the need to translate the request and responses between two SOAP endpoints. Such a use case could be implemented using two XSLT endpoints and an EIP StaticRoutingSlip. However, there are some drawbacks, as the operation is lost in the process, and a static routing slip can not be used to process InOnly exchanges.
<saxon:proxy service="test:proxy" endpoint="endpoint" resource="classpath:transform-in.xsl" outResource="classpath:transform-out.xsl" faultResource="classpath:transform-fault.xsl"> <saxon:target> <saxon:exchange-target service="test:echo" /> </saxon:target> </saxon:proxy>
Endpoint Attributes
Name |
Type |
Description |
Required |
---|---|---|---|
resource |
the spring resource pointing to the XSLT stylesheet used to transform the input message |
no |
|
outResource |
the spring resource pointing to the XSLT stylesheet used to transform the output message |
no |
|
faultResource |
the spring resource pointing to the XSLT stylesheet used to transform the fault message |
no |
|
expression |
expression used to dynamically load the stylesheet. If set, it will prevail against all resource, outResource and faultResource attributes |
no |
|
wsdlResource |
if set, the wsdl will be retrieved from the given Spring resource |
no |
|
transformerFactory |
TransformerFactory |
TraX factory to create transformers |
defaults to Saxon implementation |
configuration |
Saxon configuration |
no |
|
result |
String |
Output result type |
defaults to |
copyAttachments |
boolean |
|
defaults to |
copyProperties |
boolean |
|
defaults to |
copySubject |
boolean |
|
defaults to |
target |
ExchangeTarget |
the destination where the transformed exchange will be sent to |
yes |
XQuery Endpoint
The XQuery endpoint can be used to apply a selected XQuery to the input document.
Simple XQuery:
<saxon:xquery service="test:xquery" endpoint="endpoint" resource="classpath:query.xq" />
Inlined XQuery with specific output configuration:
<saxon:xquery service="test:xquery-inline" endpoint="endpoint"> <saxon:query> for $x in /bookstore/book where $x/price > 30 return $x/title </saxon:query> <saxon:outputProperties> <saxon:property key="{http://saxon.sf.net/}wrap-result-sequence">yes</saxon:property> </saxon:outputProperties> </saxon:xquery>
Dynamic selection of XQuery:
<saxon:xquery service="test:xquery-dynamic" endpoint="endpoint"> <saxon:expression> <bean class="org.apache.servicemix.expression.PropertyExpression"> <property name="property" value="xquery.source" /> </bean> </saxon:expression> </saxon:xquery>
Endpoint attributes
Name |
Type |
Description |
Required |
---|---|---|---|
query |
String |
inlined XQuery |
one of (query, resource, expression) |
resource |
the spring resource pointing to the XQuery |
one of (query, resource, expression) |
|
expression |
expression used to dynamically load the xquery |
one of (query, resource, expression) |
|
wsdlResource |
if set, the wsdl will be retrieved from the given Spring resource |
no |
|
outputProperties |
Map |
Saxon specific output properties |
no |
configuration |
Saxon configuration |
no |
|
result |
String |
Output result type |
defaults to |
copyAttachments |
boolean |
|
defaults to |
copyProperties |
boolean |
|
defaults to |
copySubject |
boolean |
|
defaults to |