XSLT

This interceptor allows the execution of transformations in the requests and responses through XSLT 2.0 (Extensible Stylesheet Language Transformations).

How it works

The interceptor must be configured with a script, which, in turn, will be executed in the body of the request.

The XSLT interceptor allows transformations from XML only. If the body is in JSON format, it will be automatically converted into XML before XSLT is executed.

Configuring the interceptor

To configure the interceptor, you must include the script to be executed into the Content field.

You can use header, path or query parameters in the execution of the interceptor. To do this, use the variables $header.HEADER_NAME, $queryParam.QUERY_NAME and $pathParam.PATH_NAME.

You can see an example of script below.

The option Abort request if fail can be selected, aborting the call process in case of error when the interceptor runs.

xslt

Example of script

Below is an example of a transformation creating a new body into the request, by taking a value from a JSON that was sent by the client and a value for each parameter:

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:wsx="http://www.webservicex.net"
        exclude-result-prefixes="xs xsi xsl"
        version="2.0">
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/" >
        <soap:Envelope>
            <soap:Header/>
            <soap:Body>
                <wsx:GetWeatherByPlaceName>
                    <wsx:BodyValue>
                        <xsl:value-of select="tool/name" />
                    </wsx:BodyValue>
                    <wsx:HeaderValue>
                        <xsl:value-of select="$header.type" />
                    </wsx:HeaderValue>
                    <wsx:QueryValue>
                        <xsl:value-of select="$queryParam.id" />
                    </wsx:QueryValue>
                </wsx:GetWeatherByPlaceName>
            </soap:Body>
        </soap:Envelope>
    </xsl:template>
</xsl:stylesheet>

Imagining that the XSLT interceptor is inserted in the flow, it will transform the body of this request:

POST /api?id=123
header type:xml
{
  "tool": {
    "name": "API Suite",
    "since": "2012"
  }
}

And this will be the new body created:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:wsx="http://www.webservicex.net">
    <soap:Header/>
    <soap:Body>
        <wsx:GetWeatherByPlaceName>
            <wsx:BodyValue>API Suite</wsx:BodyValue>
            <wsx:HeaderValue>xml</wsx:HeaderValue>
            <wsx:QueryValue>123</wsx:QueryValue>
        </wsx:GetWeatherByPlaceName>
    </soap:Body>
</soap:Envelope>
Thanks for your feedback!
EDIT

Share your suggestions with us!
Click here and then [+ Submit idea]