tags:

views:

50

answers:

2

Hi folks, Since disable-output-escaping doesn't work on firefox (and isn't going to), whats the next best way of including raw markup in the output of an XSTL transform?

(Background: I've got raw HTML in a database that I want to wrap in XML to send to a browser to render. I've got control of both the XML and the stylesheet, but no control of the HTML, which may be badly formed (even for HTML!))

Thanks

A: 

You may put the offending text in a CDATA section.

For example, this is a wellformed XML document:

<t><![CDATA[M & M < sufficient]]></t>

Here is an XSLT transformation, that puts the text nodes of selected elements (<t>) in CDATA sections:

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
 <xsl:output omit-xml-declaration="yes" indent="yes" />
 <xsl:output cdata-section-elements="t"/>

 <xsl:template match="node()|@*">
     <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
     </xsl:copy>
 </xsl:template>

</xsl:stylesheet>

The result is:

<t><![CDATA[M & M < sufficient]]></t>

Without the <xsl:output cdata-section-elements="t"/> instruction the result would be:

<t>M &amp; M &lt; sufficient</t>
Dimitre Novatchev
+1  A: 

XSLT is not about markup, it's about tree.

In XSLT1 you can't take a malformed input. In XSLT2 you can, but you loose xpath navegation of course.

So, without "disable-output-escaping" mechanism you can't output a posible malformed tree. And that's a feature!

Alejandro
Rats, I thought this was going to be the answer, but I was hopeing for something else. Ah, well.
Moose Morals