[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Output CDATA tags

Subject: Re: Output CDATA tags
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 28 Jan 2005 13:58:58 GMT
cdata tags
there is nothing in the XPath data model that corresponds to a CDATA
section, CDATA is just a falg to the parser to treat < and & as
characters rather than markup. 

When you have

	<xsl:template match="td" mode="markup">
		<xsl:text><![CDATA[</xsl:text>
		<xsl:copy-of select="child::node()"/>
		<xsl:text>]]></xsl:text>
	</xsl:template>


The XML parser treats this in the same way as


	<xsl:template match="td" mode="markup">
		<xsl:text>&lt;/xsl:text>
		&lt;xsl:copy-of select="child::node()"/>
		&lt;xsl:text></xsl:text>
	</xsl:template>

and that is what the XSLT engine sees, which is why you get the result
you get.

Going from


<p><span>xxx</span>...</p>

to

<![CDATA[<p><span>xxx</span>...</p>]]>

is exactly the same as going from

<p><span>xxx</span>...</p>

to

&lt;p>&lt;span>xxx&lt;/span>...&lt;/p>

and you coude it in the same way, with a template that does something
like

<xsl:template match="*">
  <xsl:text>&lt;</xsl:text>
  <xsl:value-of seelct="name()"/>
  <xsl:text>&gt;</xsl:text>
  <xsl:apply-templates/>
  <xsl:text>/&lt;</xsl:text>
  <xsl:value-of seelct="name()"/>
  <xsl:text>&gt;</xsl:text>
</xsl:template>

(more complete examples (eg handling attributes) in the faq or archives
of this list)

If you want the serialiser to use the CDATA form rather than &lt;
(although you shouldn't really care which it uses) add
cdata-section-elements="td"
to your xsl:stylesheet element.



David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.