CDATA output problem

O

ofuuzo1

I have an output xml doc that includes a CDATA section. The CDATA
section is static. so my XSLT template looks something like;
<xsl:stylesheet..>
<xsl:template..>
<![CDATA[<item1>]]>
.....

of course, there is some transformation in other parts of the
document, but I need the CDATA section to simply be copied as text to
the output doc. I have tried xsl:text, xsl:copy, but nothing seems to
work, they all strip the CDATA and write out just

&lt;item &gt;

I need help.I am using php5 + dom.

Thanks
Ofuuzo
 
J

Joseph Kesselman

As far as XML, and XSLT, are concerned <![CDATA[]]> markup is purely a
syntactic detail.
<![CDATA[<item1>]]>
is semantically identical to
&lt;item1&gt;
and no XML-based application should ever care about the difference
between them. XSLT discards that distinction during processing.

If you're forced to deal with a broken application which does care about
the difference, or if you're trying to be kind to inexperienced human
readers. it is possible to explicitly tell XSLT that the text content of
certain elements should be generated using <![CDATA[]]> syntax, via the
cdata-section-elements property of the xsl:eek:utput element. For example,
if you wanted the content of all <script> and <sample> elements to be
output this way, your stylesheet could say:
<xsl:eek:utput cdata-section-elements="sample script">
(along with any other output directives, of course).

CAVEAT: This is only a hint. XSLT is not required to honor this request,
and even if it does so the next application you pass your XML data to
may once again discard the distinction. The real "right answer" is to
fix whatever downstream application is asking you to use CDATA Sections
in the first place.
 
P

Peter Flynn

I have an output xml doc that includes a CDATA section. The CDATA
section is static. so my XSLT template looks something like;
<xsl:stylesheet..>
<xsl:template..>
<![CDATA[<item1>]]>
.....

of course, there is some transformation in other parts of the
document, but I need the CDATA section to simply be copied as text to
the output doc. I have tried xsl:text, xsl:copy, but nothing seems to
work, they all strip the CDATA and write out just

&lt;item &gt;

I need help.I am using php5 + dom.

http://xml.silmaril.ie/authors/cdata/

///Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top