[xsl] Transform XML into CDATA

Subject: [xsl] Transform XML into CDATA
From: Verakso <verakso@xxxxxxxxx>
Date: Tue, 14 Feb 2006 16:25:07 +0100
I have some problems getting this right.

In a FlashViewer, I need to feed some xml data, however some of the
data needs to be in a CDATA section, like:

	<CAPTION><![CDATA[Image info goes here.<BR>Here is the comment<BR><A
href="images/picture.jpg" target="_blank">
<U>Open image in new window</U></A>]]></CAPTION>

The original data is in xml like:
	<item name="File">picture.jpg</item>
	<item name="Desc">Image info goes here</item>
	<item name="Comment">Here is the comment</item>

Now, I have been trying to accomplish this be searching the archives
on this list, and came up with some xlt that uses
cdata-section-elements="CAPTION" and looks like this.

<xsl:template match="record" mode="image">
	<xsl:element name="IMAGE">
		<xsl:element name="NAME">
			<xsl:value-of select="item[1]"/>
		<xsl:element name="CAPTION">
			<xsl:value-of select="item[2]"/>
			<xsl:if test="normalize-space(item[3])">
				<xsl:value-of select="'&lt;BR&gt;'" disable-output-escaping="yes"/>
				<xsl:value-of select="item[3]"/>
			<xsl:value-of select="'&lt;BR&gt;'" disable-output-escaping="yes"/>
			<xsl:element name="a">
				<xsl:attribute name="href"><xsl:value-of
				<xsl:attribute name="target">_blank</xsl:attribute>
				<U>Open image in new window</U>

But this produces only a "half" CDATA section like this:
	<CAPTION><![CDATA[Image info goes here<BR>Here is the
comment<BR>]]><a href="picture.jpg" target="_blank">
		<U>Open image in new window</U>

How can I make all the data in the CAPTION element as CDATA?


BTW: The FlashViewer i am using is called SimpleViewer from

Current Thread