Click to See Complete Forum and Search --> : xslt - Stopping output Escaping!


acestuff
06-15-2010, 09:08 AM
I have an xsl stylesheet.

I want to populate it (is that the correct termonology?) with data from a xml file to form a HTML page.

The data is HTML like:
<data><div>Test</div></data>
<data><b>Data includes HTML element</b></data>

However when the xsl is populated, the tags are escaped - I want the browser to render them as HTML tags. I have tried:
<xsl:output method="html"/>
<xsl:value-of select="comment" disable-output-escaping="yes"/>

But these don't work (a cross browser solution is required.)

Anyone have any suggestions?
Many thanks,
Colin


Note: the full story is much more complicated with stuff been created with Javascript but this is definately where the problem lies...

acestuff
06-15-2010, 06:26 PM
I've looked into this and have concluded:
Firefox does not support "disable-output-escaping" (which is really anoying as all the other major browser do!)

The only fix I've come up with is letting Firefox do it's parsing and escpaing the tags then rebuiling them with javascript afterwards:

if (navigator.userAgent.indexOf("Firefox") != -1) {
var interface = /*xslt populatates the xsl with xml data and returns in div*/;

var content = interface.innerHTML;
content = content.replace(/&lt;/gi, "<");
content = content.replace(/&gt;/gi, ">");
content = content.replace(/&amp;#60;/gi, "&lt;");
content = content.replace(/&amp;#62;/gi, "&gt;");
interface.innerHTML = content;
}


It works nicely in my situation as everything is javascript so this is just an addition after the XSLT. I can't imagine this is the best fix if you're not dealing in javascript.

However, I'm happy. Unless anyone's got any better suggestions, case closed!