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.
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:ValorBody>
<xsl:value-of select="tool/name" />
</wsx:BodyValue>
<wsx:HeaderValue>
<xsl:value-of select="$header.content-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 Content-Type:application/json
{
"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:ValorBody>API Suite</wsx:ValorBody>
<wsx:ValorHeader>application/json</wsx:ValorHeader>
<wsx:ValorQuery>123</wsx:ValorQuery>
</wsx:GetWeatherByPlaceName>
</soap:Body>
</soap:Envelope>
Share your suggestions with us!
Click here and then [+ Submit idea]