Re: [xsl] Handling CDATA element
At 2006-02-09 17:21 +0100, Thorsten Scherler wrote:
I have a question regarding the CDATA element.
CDATA isn't an element, it is merely syntactic sugar for the human
reader and does not impact on the *information* in the XML document.
XSLT and XPath, therefore, do not distinguish any information marked
up using the CDATA syntactic construct.
<description><![CDATA[html-to-document.xsl no longer converts content to
an XDoc. Instead it renders converts documents to XDoc, instead it
allows H1, H2 etc. elements to pass through.
Fine ... that is just a bunch of text that happens to have a bunch of
Now in my xsl I have something like the following to preserve the markup
of the cdata (it can contain any html markup).
<xsl:value-of select="description" disable-output-escaping="yes" />
Fine, but that is merely indicating to the serialization that the
sensitive markup characters are not to be escaped. Which cannot be
used in an XML result, but can surely be used in an HTML result,
which supports your use of any HTML markup in the information.
If you remove @disable-output-escaping then it will transformed to
Correct, in order to escape the sensitive markup characters.
That looses the markup information but result in well-formed markup.
"loses"? No, the angle brackets are all still there, they are just
escaped ... and using disable-output-escaping on those angle brackets
will produce the same HTML result as using disable-output-escaping on
information captured using CDATA markup.
I prefer well-formed over well-presented, but best would be both. ;-)
"presented"? Do you mean in the XML document's text content? I'm
guessing perhaps you mean that you want to see "<" instead of "<"
in the text content of your XML document, probably because human
eyeballs are looking at it.
I am unsure how to fix that, has somebody an idea?
Fix what? I'm not sure where your problem is.
Note that if you wanted your XML transformation for all <description>
elements to be serialized using a CDATA section, that is available in
<xsl:output> using the cdata-section-elements="description" attribute.
TIA for any informations
I hope this helps.
. . . . . . . . . . . . Ken
Upcoming XSLT/XSL-FO hands-on courses: Washington,DC 2006-03-13/17
World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers: http://www.CraneSoftwrights.com/legal