USER MANUALS

XSLT Transformations

In an environment with existing SOAP and REST clients, you do not need to modify these clients to work with Virtual DataPort Web services. You can define XSLT stylesheets (XSL Transformations) to transform the incoming requests in order to adapt them to the format that the Denodo Web services expect. You can also define stylesheets to transform the responses of these services, before sending them to the existing clients.

Virtual DataPort uses the Saxon-HE XSLT and XQuery processor to process XSLT transformations. This processor supports the XSLT 2.0 specification.

Follow these steps to define XSLT transformations for a Web service:

  1. In the Settings tab of the “SOAP Web service” or “REST Web service”, select the operation (Operation name) or view (Resource configuration) you want to transform and click XSLT Transformation.

  2. Select the Input XSLT Transformation check box and write the stylesheet. This stylesheet will be applied to the incoming requests, to transform them into the format expected by the Virtual DataPort Web service. If this check box is cleared, the input will not be modified.

  3. Select the Output XSLT Transformation check box and write the stylesheet. This stylesheet will be applied to the responses generated by the Denodo Web service, to transform them into the format expected by the existing SOAP client. If this check box is cleared, the input will not be modified.

  4. Only for SOAP Web services: if the existing SOAP client sends the parameter SOAPAction with its requests and the parameter cannot be changed, select the Incoming SOAPAction check box and write it.

  5. Click Ok and repeat these steps for each operation of the Web service that you want to transform.

By default, the XSLT transformations are applied to data but not to the error messages returned by the Web service. Select Apply output XSLT to error messages if you want the Service to apply the transformations to error messages as well. In REST Web services, this option only affects the XML representation of the views.


Examples

Example #1 Converting XML to CSV

If you configure a REST web service with the output XSL transformation below, when the client requests the XML representation of a view, the response will be a CSV file. The HTTP header Content-type of the response will be text/plain.

XSL transformation that converts the XML response into a CSV
<xsl:stylesheet version="1.0"
                     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output method="text"
                     media-type="text/plain"
                     encoding="UTF-8" />
     <xsl:strip-space elements="*" />
     <xsl:template match="/*/child::*">
             <xsl:for-each select="child::*">
                     <xsl:if test="position() != last()">"<xsl:value-of select="normalize-space(.)"/>",    </xsl:if>
                     <xsl:if test="position()  = last()">"<xsl:value-of select="normalize-space(.)"/>"<xsl:text>&#xD;</xsl:text>
                     </xsl:if>
             </xsl:for-each>
     </xsl:template>
</xsl:stylesheet>

Note

This example has limitations since it is not possible to represent compound values (registers and arrays) with comma-separated values.

Example #2: Converting XML to JSON

If you configure a REST web service with the output XSL transformation below, when the client requests the XML representation of a view, the response will be the equivalent JSON document. The HTTP header Content-type of the response will be application/json.

XSL transformation that converts the XML response into a JSON
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output media-type="application/json"/>

    <xsl:template match="*">

        <xsl:element name="{local-name()}">
            <xsl:apply-templates select="node()|@*"/>
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>

An XSL transformation like this one is useful if you have an application that needs to obtain data in JSON from a Denodo web service but the application requires this JSON document to have a different structure than the one produced by the web service. In this scenario, you can set the default representation of the web service to be JSON and set this XSLT.

Notes

  • A REST web service only applies the output XSL transformations to the response when both of these conditions are met:

    1. The client requests the XML representation of the data. That is, the URL of the request has the parameter $format=xml or the request includes the HTTP header Accept: application/xml. If the client requests another representation (e.g. HTML), the service does not apply the XSL transformations of the service.

    2. The web services do not apply the transformation over the list of views, only over the data of a view (e.g. http://denodo-server.acme.com/server/customer360/ws_rest_customer360/views/customer).

  • The REST services process the declaration <xsl:output> of the output XSL transformation, not of the input XSL transformation.

  • The xsl:output declaration is optional. If used, it must always appear as a top-level element, not nested within another stylesheet module.

  • SOAP web services ignore the declaration xsl:output.

  • See appendix Transforming Incoming/Outgoing Soap/Rest Messages with XSLT Stylesheets for more details on how to write XSL transformations.

Add feedback