I need to do XSL transformation in the browser using JavaScript.
When i'm doing this in the modern browsers, such as FF or Chrome i can do something like this:
var proc = new XSLTProcessor();
proc.importStylesheet(xslDoc);
return proc.transformToFragment(xmlDoc, targetDocument);
But with IE i can only transform to a new document
var newDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.transformNodeToObject(xslDoc, newDoc);
return newDoc;
... or transform to text
return xmlDoc.transformNode(xslDoc);
Transforming to text leading to huge perfomace issue开发者_JAVA百科s (i need to append the result to my current document's DOM tree), transforming to new doc leading to doing adopt/importNode at last.
Is there a better way of doing XSL transformation in IE with further appending result to a DOM tree?
Just an idea ... why not add this line to your xml file :
<?xml-stylesheet type="text/xsl" href="your_stylesheet_file.xsl"?>
like shown here : http://www.w3schools.com/xsl/xsl_transformation.asp
This would let the browser do the transformation and then you'll load this xml in a iframe that you would parse ?
<iframe src="your.xml" onload="parse_it()" ></iframe>
精彩评论