Transform JSON To XML In API Gateway

Hi Everyone,

I am using API Gateway version 10.15 and I am trying to transform my response from JSON to XML using XSLT in response processing policy. But my response is always in json despite of my payload. How can I transform my JSON response to XML. This is my XSLT.

<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:strip-space elements="*"/>
  <xsl:output method="xml"/>
    <!-- Identity transform -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="*[not(node()) or text() = 'null']"/>
</xsl:stylesheet>

What is the value passing in Accept header parameter in the request and give us the details about response policy defined for the API?

In header Accept value is “/

This is the payload defined in response processing.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

    <invoicedetails>
        <invoiceid>
           12345
        </invoiceid>
        <paymentreference>
            269467
        </paymentreference>
        <referenceid>
            fa51c8b6
        </referenceid>
        <externaltransactionid>
            2112
        </externaltransactionid>
        <receiver>
            ID:111/11
        </receiver>
        <creator>
            ID:111/11
        </creator>
        <amount>
            <amount>
                100.00
            </amount>
            <currency>
                EUR
            </currency>
        </amount>
        <status>
		<status1>
		PENDING
		</status1>
            
        </status>
        <creationdatetime>
            2022-11-29T15:24:27.920+01:00
        </creationdatetime>
        <lastupdatedatetime>
            2022-11-29T15:24:27.920+01:00
        </lastupdatedatetime>
        <expirydatetime>
            2022-11-29T16:24:27.920+01:00
        </expirydatetime>
    </invoicedetails>

This is response processing configurations.

See if this tutorial helps.

It shows how json is transformed using XSLT.

https://youtu.be/h670ZpoC-Zc

1 Like

Hi @franklinantony,

Thank you for your response but this is JSON to JSON transformation. We need to transform JSON to xml

Similar topic covered here : WM API Gateway - Request Transformation Payload - From JSON to XML? - #10 by rmg

HTH
Bharath

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.