RE: [xsl] unparsed CDATA maintain HTML

Subject: RE: [xsl] unparsed CDATA maintain HTML
From: "Andreas L. Delmelle" <a_l.delmelle@xxxxxxxxxx>
Date: Sun, 14 Dec 2003 18:27:29 +0100
> -----Original Message-----
> From: George @dante
>
> lets say for a reason (maybe a wrong one) we have an XML file
> that contains
> a text element
>
> <text><![CDATA[I <i>have/<i> to add some <b>HTML</b> here is ]]></text>
>
> and at the result XHTML I want to maintain these. I thought that CDATA
> should be enough and applying templates would maintain these but
> I get &lt;
> &gt; and that resulting to the <i>s and <b>s being shown as at the end
>

Enclosing <> in <!CDATA[]> basically comes down to the same thing as having
raw &lt; and &gt; in the text element, so your text looks like :

<text>I &lt;i&gt;have&lt;/i&gt; to add some &lt;b&gt;HTML&lt;/b&gt; here is
</text>

to the parser.

Question is whether you really need that. Since your handling XML anyway,
there's no reason you couldn't just have this in your source file:

<text>I <i>have</i> to add some <b>HTML</b> here is </text>

and a simple <xsl:copy-of select="." /> in the template for handling
'text'-elements, will result in the above being copied into the result
document.

Alternatively, you could use 'disable-output-escaping', but that's only to
be used as a last resort. I think you're way better of removing the
<!CDATA[]> markup altogether (if possible).


Cheers,

Andreas


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


Current Thread