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.

Using servicemix-saxon as a standard JBI component

Installation

Installing the servicemix-saxon component can be done in several ways:

  • drop the installer zip in an hotdeploy directory monitored by ServiceMix
  • using ant tasks

Note that when using ant tasks, the component is not started, you will have to start it manually using ant tasks or a console.

Service Unit packaging

A service unit will typically consist in:

  • an xbean.xml configuration file
  • the associated xslt / xquery document

Content of xbean.xml file to be packaged as a SU

<beans xmlns:saxon="http://servicemix.apache.org/saxon/1.0">

  ... add endpoints here ...

</beans>

Using servicemix-saxon in a ServiceMix xml configuration file

<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
       xmlns:saxon="http://servicemix.apache.org/saxon/1.0">

  <sm:container ...>
    <sm:activationSpecs>
      <sm:activationSpec>
        <sm:component>
          <saxon:component>
            <saxon:endpoints>

              ... add saxon endpoints here ...

            </saxon:endpoints>
          </saxon:component>
        </sm:component>
      </sm:activationSpec>
      ...
    </sm:activationSpecs>
  </sm:container>
  ...

</beans>

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 Spring resource the spring resource pointing to the XSLT stylesheet one of (resource, expression)
expression ServiceMix expression expression used to dynamically load the stylesheet one of (resource, expression)
wsdlResource Spring resource 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 Saxon configuration no
result String Output result type defaults to dom, possible values are dom, bytes, string
copyAttachments boolean   defaults to true
copyProperties boolean   defaults to true
copySubject boolean   defaults to true

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 Spring resource the spring resource pointing to the XQuery one of (query, resource, expression)
expression ServiceMix expression expression used to dynamically load the xquery one of (query, resource, expression)
wsdlResource Spring resource if set, the wsdl will be retrieved from the given Spring resource no
outputProperties Map Saxon specific output properties no
configuration Saxon configuration Saxon configuration no
result String Output result type defaults to dom, possible values are dom, bytes, string
copyAttachments boolean   defaults to true
copyProperties boolean   defaults to true
copySubject boolean   defaults to true