Skip to Content
0
Former Member
Apr 14, 2010 at 01:29 PM

Reading the data from CDATA.

693 Views

Hi Experts, attn: Stefan.

I have a requirement to convert a string XML to XML using XSLT. With the inputs from Stefan I have got my XSLT mapping working fine and tested it in XMLSpy. It works fine.

The problem is, when I test my Interface mapping in PI and input test XML in a string Field, PI on its own, wraps data into CDATA tag as.

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

<ns0:MT_SourceString xmlns:ns0="http://abc.com">
   <Str><![CDATA[<catalog>
<cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year></cd> 
<cd> <title>Empire Burlesque2</title> <artist>Bob Dylan2</artist> <country>USA</country> <company>Columbia2</company> <price>10.90</price> <year>1985</year> </cd> 
<cd> <title>Empire Burlesque3</title> <artist>Bob Dylan3</artist> <country>USA</country> <company>Columbia3</company> <price>10.90</price> <year>1985</year> </cd> 
</catalog>
]]>

Now XSLT ignores all the data in CDATA and i get nothing in output. 😔

<?xml version="1.0" encoding="UTF-8"?><ns0:MT_TargetCatalog xmlns:a="http://www.sdn.com/xslt" xmlns:ns0="http://abc.com"/>

XSLT Code:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="http://www.sdn.com/xslt">
<xsl:output method="xml" omit-xml-declaration="no"/>
<xsl:template match="/">
<ns0:MT_TargetCatalog xmlns:ns0="http://abc.com">
<xsl:for-each select="//cd">
<xsl:copy-of select="."  />
</xsl:for-each>
</ns0:MT_TargetCatalog>
</xsl:template>
</xsl:stylesheet>

Please sugest how can I read the data from CDATA tag of XML?

Kind Regards,

Abhi.