Map SOAP Response to a different SOAP response structure

Hi @All,

As a Beginner in apigee.

1. I have created SOAP Service using pass-through proxy option with XSD validation.

2. Now I want to transform the SOAP response to a different SOAP format.

E.g.,

SOAP Response Received:

<?xml version="1.0"?>

<note>

<bk_id>12345</bk_id>

<bk_ver>Gane</bk_ver>

<bk_loc>London</bk_loc>

<bk_notes>Please get your ID proof along with you</bk_notes>

</note>

I want to modify the response to below format

<?xml version="1.0"?>

<Booking>

<BookingID>12345</BookingID>

<BookingVersion>Gane</BookingVersion>

<Location>London</Location>

<Notes>Please get your ID proof along with you</Notes>

</Booking>

3. Am I suppose to write any custom code using node.js or Java etc..

4. Will I be able to use any of the coding language in trial version of Apigee Edge?

Please provide your suggestions

Thank you.

Solved Solved
0 2 282
1 ACCEPTED SOLUTION

sidd-harth
Participant V

You need to use XSLT Policy for XML >> XML transformation.

https://docs.apigee.com/api-platform/reference/policies/xsl-transform-policy

The below sample XSL should give you the expected response. Modify it as required.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:output method="text" />
   <xsl:variable name="newline">
      <xsl:text />
   </xsl:variable>
   <xsl:template match="/">
      <xsl:text><Booking></xsl:text>
      <xsl:value-of select="$newline" />
      <xsl:text><BookingID></xsl:text>
      <xsl:for-each select="note/bk_id">
         <xsl:value-of select="." />
         <!-- <xsl:value-of select="$newline"/> -->
      </xsl:for-each>
      <xsl:text></BookingID></xsl:text>
      <xsl:text><Location></xsl:text>
      <xsl:for-each select="note/bk_loc">
         <xsl:value-of select="." />
         <!-- <xsl:value-of select="$newline"/> -->
      </xsl:for-each>
      <xsl:text></Location></xsl:text>
      <xsl:text><BookingVersion></xsl:text>
      <xsl:for-each select="note/bk_ver">
         <xsl:value-of select="." />
         <!-- <xsl:value-of select="$newline"/> -->
      </xsl:for-each>
      <xsl:text></BookingVersion></xsl:text>
      <xsl:text><Notes></xsl:text>
      <xsl:for-each select="note/bk_notes">
         <xsl:value-of select="." />
         <!-- <xsl:value-of select="$newline"/> -->
      </xsl:for-each>
      <xsl:text></Notes></xsl:text>
      <xsl:text></Booking></xsl:text>
   </xsl:template>
</xsl:stylesheet>

View solution in original post

2 REPLIES 2

Aplogies, I need to transform SOAP Response to a XML format

sidd-harth
Participant V

You need to use XSLT Policy for XML >> XML transformation.

https://docs.apigee.com/api-platform/reference/policies/xsl-transform-policy

The below sample XSL should give you the expected response. Modify it as required.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:output method="text" />
   <xsl:variable name="newline">
      <xsl:text />
   </xsl:variable>
   <xsl:template match="/">
      <xsl:text><Booking></xsl:text>
      <xsl:value-of select="$newline" />
      <xsl:text><BookingID></xsl:text>
      <xsl:for-each select="note/bk_id">
         <xsl:value-of select="." />
         <!-- <xsl:value-of select="$newline"/> -->
      </xsl:for-each>
      <xsl:text></BookingID></xsl:text>
      <xsl:text><Location></xsl:text>
      <xsl:for-each select="note/bk_loc">
         <xsl:value-of select="." />
         <!-- <xsl:value-of select="$newline"/> -->
      </xsl:for-each>
      <xsl:text></Location></xsl:text>
      <xsl:text><BookingVersion></xsl:text>
      <xsl:for-each select="note/bk_ver">
         <xsl:value-of select="." />
         <!-- <xsl:value-of select="$newline"/> -->
      </xsl:for-each>
      <xsl:text></BookingVersion></xsl:text>
      <xsl:text><Notes></xsl:text>
      <xsl:for-each select="note/bk_notes">
         <xsl:value-of select="." />
         <!-- <xsl:value-of select="$newline"/> -->
      </xsl:for-each>
      <xsl:text></Notes></xsl:text>
      <xsl:text></Booking></xsl:text>
   </xsl:template>
</xsl:stylesheet>