- 2 minutes to read

XML to XML

In this XSLT based example, the Body part of a SOAP message is stripped from its' Envelope

With Nodinite you can allow end-users to view message payload in other formats using one or more Stylesheets.

You can use this as an example to style any XML-based message into another XML message. This can be a very useful feature to help you remove sensitive information from end-users.

XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" exclude-result-prefixes="soap">
  <xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="UTF-8" indent ="yes"/>
  <xsl:template match="/">
    <xsl:apply-templates select="soapenv:Envelope/soapenv:Body/*"/>
  </xsl:template>
  <xsl:template match="*">
    <xsl:element name="{local-name()}">
      <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
  </xsl:template>

  <xsl:template match="@*">
    <xsl:attribute name="{local-name()}">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
</xsl:stylesheet>

Input XML

The following data is an example of a SOAP message with an Envelope and a Body:

<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
	<soap:Body>
    <Orders>
      <Order state="OK">
        <Id>1337</Id>
      </Order>      
    </Orders>
	</soap:Body>
</soap:Envelope>

Output XML

If you apply the example XSLT on the Input XML, the following output is the result:

<Orders>
  <Order state="OK">
    <Id>1337</Id>
  </Order>
</Orders>

Next Step