IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

Keep CDATA in Output Options · View
feiyang
Posted: Wednesday, February 3, 2010 12:41:25 PM
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!
island
Posted: Wednesday, February 3, 2010 1:18:52 PM
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>

feiyang
Posted: Wednesday, April 21, 2010 8:43:25 AM
Rank: Newbie

Joined: 6/24/2008
Posts: 9
Thank you for your helpful posting! I will try that.
Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.