This documentation is for WSO2 Enterprise Service Bus version 5.0.0. For the latest ESB, view the latest WSO2 Enterprise Integrator documentation.

All docs This doc

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagexml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Header> 
    <soapenv:Body> 
        <people> 
            <person> 
                <firstname>Isuru</firstname> 
                <lastname>Udana</lastname> 
                <gender>Male</gender> 
                <age>26</age> 
                <country>SriLanka</country> 
            </person> 
            <person> 
                <firstname>Ishan</firstname> 
                <lastname>Jayawardena</lastname> 
                <gender>Male</gender> 
                <age>26</age> 
                <country>SriLanka</country> 
            </person> 
        </people> 
    </soapenv:Body> 
</soapenv:Header></soapenv:Envelope>

Example 4 - Adding CDATA to be displayed in the output

Follow the steps below to add CDATA to display them in the output without processing them via the XSLT transformation.

  1. Create a file named XMLInputFactory.properties inside the <ESB_HOME> directory, and include the following property in it: javax.xml.stream.isCoalescing=false
  2. Add the <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/> attribute to the XSL stylesheet.
  3. In the XSL stylesheet, wrap the encoded CDATA within the <xsl:text> elements with the disable-output-escaping="yes" parameter as shown below.

    Code Block
    <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
    <xsl:copy-of select="*"/>
    <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>

The following is an example of a XSL stylesheet, which includes CDATA to be displayed in the output.

Code Block
languagexml
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
    <xsl:template match="/">
      <root>
<xsl:copy>
<xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
<xsl:copy-of select="*"/>
<xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
</xsl:copy>
      </root>
</xsl:template>
</xsl:stylesheet>

You can use the following Synapse configuration to process the above XSL stylesheet via a XSLT mediator. In the above configuration, the XSL stylesheet is defined as a local entry named XSLTTest, and it is referred in the XSLT mediator configuration via the key attribute within the proxy service named XSLTProxy.

Code Block
languagexml
<proxy name="XSLTProxy" startOnLoad="true" transports="http https">
        <description/>
        <target>
            <inSequence>
                <xslt key="XSLTTest"/>
                <log level="full"/>
                <respond/>
            </inSequence>
        </target>
</proxy>
<localEntry key="XSLTTest">
        <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
           <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
           <xsl:template match="/">
           <root>
              <xsl:copy>
                <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
                <xsl:copy-of select="*"/>
                <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
              </xsl:copy>
           </root>
           </xsl:template>
       </xsl:stylesheet>
        <description/>
</localEntry>

For example, pass the following payload to the XSLTProxy proxy service of the above configuration.

Code Block
languagexml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <abc>testabc</abc>
   </soapenv:Body>   
</soapenv:Envelope>

You view the output with the CDATA displayed as follows in the Console logs of the WSO2 ESB server.

Code Block
languagetext
INFO - LogMediator To: /services/XSLTProxy.XSLTProxyHttpSoap11Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:266d380f-800f-479b-bee9-c30897efe562, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
   <root xmlns="http://ws.apache.org/ns/synapse"><![CDATA[<abc xmlns="">testabc</abc>]]></root>
</soapenv:Body></soapenv:Envelope>

Samples

Sample 440: Converting JSON to XML Using XSLT

...