I've got a simple piece of javascript that adds an exslt namespace to an xsl document. However, Chrome and Firefox handle this differently. Firefox will add the namespace correctly to the root with the full
xmlns:exsl="http://exslt.org/common"
Chrome however just plunks in
exsl="http://exslt.org/common"
Did you see the difference? 'xmlns
' is gone in the latter and Chrome itself thinks the xslt is malformed: it returns null when you transform! If you correctly prefix, i.e., xmlns:exsl
and then Chrome likes it. Try the fiddle below with Firefox and then with Chrome to see the difference. Here is the simple code
var styleString = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><div>hi</div></xsl:template></xsl:stylesheet>';
var xslDoc = (new DOMParser()).parseFromString(styleString, "text/xml");
var docRoot = xslDoc.documentElement;
a = document.createAttribute("xmlns:exsl");
a.nodeValue = "http://exslt.org/common";
docRoot.setAttributeNode(a);
var xmls1 = new XMLSerializer();
var outputXHtmlString = xmls1.serializeToString(xslDoc);
document.getElementById("content").innerText = outputXHtmlString;
Use this
var styleString = '<xsl:stylesheet version="1.0" xmlns:xsl="w3.org/1999/XSL/Transform" xmlns:exsl="exslt.org/common"><xsl:template match="/"><div>hi</div></xsl:template></xsl:stylesheet>