The FastXSLT Mediator is similar to the XSLT mediator, but it uses the Streaming XPath Parser and applies the XSLT transformation to the message stream instead of to the XML message payload. The result is a faster transformation, but you cannot specify the source, properties, features, or resources as you can with the XSLT mediator. Therefore, the FastXSLT mediator is intended to be used to gain performance in cases where the original message remains unmodified. Any pre-processing performed on the message payload will not be visible to the FastXSLT mediator, because the transformation logic is applied on the original message stream instead of the message payload. In cases where the message payload needs to be pre-processed, use the XSLT mediator instead of the FastXSLT mediator.
The streaming XPath parser used in the Fast XSLT mediator does not support Xpath functions specified with the prefix "
fn: ". Examples are "
fn:count", and "
For example, if you are using the VFS transport to handle files, you might want to read the content of the file as a stream and directly send the content for XSLT transformation. If you need to pre-process the message payload, such as adding or removing properties, use the XSLT mediator instead.
In summary, following are the key differences between the XSLT and FastXSLT mediators:
|XSLT Mediator||FastXSLT Mediator|
Performs XSLT transformations on the message payload.
Performs XSLT transformations on the message stream.
|The message is built before processing. Therefore, you can pre-process the message payload before the XSLT transformation.||The message is not built before processing. Therefore, any pre-processing on the message will not be reflected in the XSLT transformation.|
|The performance is slower than the FastXSLT mediator.||The performance is faster than the XSLT mediator.|
To enable the FastXSLT mediator, your XSLT script must include the following parameter in the XSL output.
If you do not include this parameter in your XSLT when using the FastXSLT mediator, you will get the following error.
The FastXSLT mediator is a conditionally content-aware mediator.
For example, specify the XSLT by the key
transform/example.xslt, which is used to transform the message stream as shown below.
The parameters available to configure the FastXSLT mediator are as follows.
You can select one of the following options.
This specifies the registry key to refer the XSLT to. This supports static and dynamic keys.
You can click NameSpaces to add namespaces if you are providing an expression. Then the Namespace Editor panel would appear where you can provide any number of namespace prefixes and URLs used in the XPath expression.
You can also configure the mediator using XML. Click switch to source view in the Mediator window.
The following example applies a simple XSLT stylesheet to a message payload via the FastXSLT mediator. The FastXSLT mediator reads values from the current XML payload using XPath and populates them into the stylesheet to create a new or different payload as the response. The ESB configuration of the API of this example is as follows:
Follow the steps below to specify the stylesheet as a Registry entry in the above API.
- Double click on the API and click the following link in the Properties tab.
- Click Create & point to a new resource... link.
- Enter the following details to create the empty XSL file in which you enter the stylesheet, in the Registry.
Double-click the stylesheet file in the Project Explorer, and add the following stylesheet as the content of the XSL file.
Pass the following XML payload using SOAP UI.
You pass this payload into the XSLT mediator specifying a certain
drinkName as a parameter to the style sheet. For example, the following payload passes the
drinkName as 'Coffee'. The style sheet traverses through the incoming payload and finds the
<lunch> elements, which contains 'Coffee' as
drinkName. When it finds matching ectries, it adds the prices of those elements under a new
<Payment> element. Therefore, when the message flow comes out of XSLT mediator, the payload changes the
<Payment> entry, where it contains the
drinkPrice values of matching elements.
You can get the URI of the REST API from the Management Console as shown below.
You receive the response as shown below.