This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: copying CDATA section from xml
- From: Mike Brown <mike at skew dot org>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Thu, 8 Aug 2002 10:28:20 -0600 (MDT)
- Subject: Re: [xsl] copying CDATA section from xml
- Reply-to: xsl-list at lists dot mulberrytech dot com
NILESH PATEL wrote:
> I have a small xml document which basically containes standard output by
> running native command on java and it only containes simple text in CDATA
> section as shown below in XML. However I don't know how to write xsl to grab
> all the details of CDATA section and write out in text format. Please help.
> If any questions then please let me know. Looking forward to resolve this.
CDATA sections are a convenience for document authors only; their only purpose
is to make it so you don't have to escape "<" and "&" characters. They are not
a part of the XPath/XSLT data model. All character data, whether it is in a
CDATA section or not, gets merged into text nodes in a node tree. For example,
<foo>1 <![CDATA[& 2 are <]]> 3</foo>
becomes two nodes:
element 'foo'
|
|___text '1 & 2 are < 3'
So your question is simply, how do you copy the the text content of your
'stdout' element. Easy:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="iso-8859-1"/>
<xsl:template match="/">
<xsl:value-of select="root/stdout"/>
</xsl:template>
</xsl:stylesheet>
- Mike
____________________________________________________________________________
mike j. brown | xml/xslt: http://skew.org/xml/
denver/boulder, colorado, usa | resume: http://skew.org/~mike/resume/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list