Moose Morals
Moose Morals

Reputation: 1648

XSLT disable output escaping when disable-output-escaping is not supported

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

Upvotes: 2

Views: 1650

Answers (2)

user357812
user357812

Reputation:

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!

Upvotes: 0

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243459

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">
 <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>

Upvotes: 1

Related Questions