XSLT Mediator

The xslt mediator applies the specified XSLT transformation to the selected element of the current message payload. The source attribute specifies which element to be selected to apply the given XSLT transfomation. In the case where the source element is not specified, it uses the first child of the soap body as the selected element. Optionally parameters could be passed into the transformations through the 'property' elements. These properties are corresponding to the XSL parameters and can be accessed during transformation by <xsl:param name="{the name of the property}" />. The 'feature' element defines any features which should be explicitly set to the TransformerFactory. The feature 'http://ws.apache.org/ns/synapse/transform/feature/dom' turns on DOM based transformations instead of serializing elements into Byte streams and/or temporary files. Though this would be better in performance than using byte streams, sometimes it may not work for all transformations.

Finally, the 'resource' element can be used to resolve XSLT imports and includes from the repository. It works in exactly the same way as the corresponding element in a <proxy> definition (Proxy Service).

Syntax

 <xslt key="string" [source="xpath"]>
   <property name="string" (value="literal" | expression="xpath")/>*
   <feature name="string" value="true| false" />*
   <resource location="string" key="string"/>*
 </xslt>

UI Configuration

Figure 1. XSLT Mediator

XSLT Mediator

  • Key : The registry key to refer the xslt. This supports static and dynamic keys. For more information refer Sample 16
  • Source: Specify in which part of message (specified in xpath) the xslt should be applied. Default is the SOAP body of the message.

Properties of the XSLT mediator

Manage the properties which would be referred from the xslt in transformation (using get-property(prop-name) xpath extension function).

Figure 2. Add Properties

  • Property Name: Name of the property.
  • Property Type: Whether it is a static value or an xpath expression.
  • Value/ Expression: The static value or the xpath expression.
  • NSEditor: Specify the namespaces that are used in the xpath expression.
  • Action: Delete the property.

Features of the XSLT mediator

Specify the features to be enabled in the XSLT transformation. Read the introduction paragraph of this guide for an example feature.

Figure 3. Add Features

XSLT Mediator - Add Features

  • Feature Name: Name of the feature.
  • Feature Value: Specify whether the feature is turn on (True) or Not (False).
  • Action: Delete the feature.

Example

 
<xslt xmlns="http://ws.apache.org/ns/synapse" key="transform/example.xslt" source="s11:Body/child" />

In this scenario the xslt can be picked by the key transform/example.xslt and the XSLT would be applied to a part of the message that is specified as a XPath expression.In this case it is applied to s11:Body/child the message