This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: copying CDATA section from xml


Thanks Mike, and list,

This solves my problem.

Nileh Patel


From: Mike Brown <mike@skew.org>
Reply-To: xsl-list@lists.mulberrytech.com
To: xsl-list@lists.mulberrytech.com
Subject: Re: [xsl] copying CDATA section from xml
Date: Thu, 8 Aug 2002 10:28:20 -0600 (MDT)

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



_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. http://www.hotmail.com


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]