|
|
Rank: Newbie
Joined: 6/24/2008 Posts: 9
|
Hello,
I have a input file with some CDATA element values. However if I use xsl:copy-of to copy all element CDATA is removed and just the values are copied into the target nodes.
Is there any way to get a 1:1 copy keeping those CDATA values?
Thank you!
|
|
Rank: Newbie
Joined: 10/28/2002 Posts: 1,283 Location: AT
|
Hi
cdata is not part of the input tree that is passed to the xslt processor so you would essentially have to manually instruct the xslt processor to process certain nodes and add a cdata section i.e. in the example below i am instructing the processor to process the element "b" and put its contents into a cdata section via the "cdata-section-elements" attribute on the xsl:output element.
INPUT file
Code:
<?xml version="1.0" encoding="UTF-8"?> <a> <b><![CDATA[<c>hello</c>]]></b> </a>
XSLT file
Code:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" cdata-section-elements="b"/> <xsl:template match="/"> <xsl:copy-of select="."> <xsl:apply-templates/> </xsl:copy-of> </xsl:template> <xsl:template match="*"> <xsl:copy-of select="."> <xsl:apply-templates/> </xsl:copy-of> </xsl:template> <xsl:template match="text()"> <xsl:copy/> </xsl:template> </xsl:stylesheet>
|
|
Rank: Newbie
Joined: 6/24/2008 Posts: 9
|
Thank you for your helpful posting! I will try that.
|
|
|
guest |