Page History

...
Code Block | ||
---|---|---|
| ||
<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.
- Create a file named
XMLInputFactory.properties
inside the<ESB_HOME>
directory, and include the following property in it:javax.xml.stream.isCoalescing=
false
- Add the
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
attribute to the XSL stylesheet. In the XSL stylesheet, wrap the encoded CDATA within the
<xsl:text>
elements with thedisable-output-escaping="yes"
parameter as shown below.Code Block <xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text> <xsl:copy-of select="*"/> <xsl:text disable-output-escaping="yes">]]></xsl:text>
The following is an example of a XSL stylesheet, which includes CDATA to be displayed in the output.
Code Block | ||
---|---|---|
| ||
<?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"><![CDATA[</xsl:text>
<xsl:copy-of select="*"/>
<xsl:text disable-output-escaping="yes">]]></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 | ||
---|---|---|
| ||
<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"><![CDATA[</xsl:text>
<xsl:copy-of select="*"/>
<xsl:text disable-output-escaping="yes">]]></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 | ||
---|---|---|
| ||
<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 | ||
---|---|---|
| ||
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
...