[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Need to wrap XML in tags


Subject: Re: [xsl] Need to wrap XML in <![CDATA[...]]> tags
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 4 Aug 2003 17:58:28 +0100


  End result:

  <CONTENT><![CDATA[
   <html>
   <head>
   <title>Resultant text from a value-of</title>
   <body>Resultant text from a value-of</body>
   </head>
   </html>]]>
   </CONTENT>


OK then my first answer holds.
The above is exactly the same as

  &lt;CONTENT>
   &lt;html>
   &lt;head>
   &lt;title>Resultant text from a value-of&lt;/title>
   &lt;body>Resultant text from a value-of&lt;/body>
   &lt;/head>
   &lt;/html>
   </CONTENT>


Just linearised differently, just as <a="b"/> is the same as <a = 'b' />
AN XSLT (or any XML) system would see these as the same input,
and in XSLT you use identical code to produce either of them (and the
system will do it one way or the other, just as you can't directy
control whether the system uses " or ' around attribute values.

When using XSLT it's best not to think of the serialisation at all
until the final stage when you can drop serialisation hints to
xsl:output.

So you want to convert elements such as html into strings with their
linearisation. there are loads of stylesheets to do this in the faq or
archives of this list, and elswehere but they all basically look like
the code I posted before

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

So once you've converted all your input tree to a single string, you
want to _ask_ the XSLt system to output that using CDATA rather than lots
of &lt; so you do that by

<xsl:output cdata-section-elements="CONTENT"/>

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. 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
________________________________________________________________________

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



Current Thread
Keywords