How do I load XSLT Stylesheets in javascript so in

2019-08-27 12:41发布

I'm loading an xslt stylesheet in javascript like this. I'm only required to support Chrome.

function loadXMLDoc(filename){
xhttp = new XMLHttpRequest();
xhttp.open("GET", filename, false);
xhttp.send("");
return xhttp.responseXML;
}

xsl = loadXMLDoc("../Stylesheets/main.xsl");
xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);

main.xsl is the main stylesheet and contains a lot of xsl:include references to other xsl stylesheets. I need to send an argument somewhere that tells javascript to resolve the include references.

I'm not using IE, but it has an ActiveXObject method like:

doc.setProperty('ResolveExternals', true);

Is there some command I can put in my code to 'Resolve Externals' to pull in the stylesheets referenced in main.xsl?

1条回答
Bombasti
2楼-- · 2019-08-27 13:04

Turns out xhttp needed to be a global variable. I'm not sure why, but it worked.

function loadXMLDoc(filename){
var xhttp = new XMLHttpRequest();
xhttp.open("GET", filename, false);
xhttp.send("");
return xhttp.responseXML;
}
查看更多
登录 后发表回答