我用下面的JavaScript代碼來顯示XML/XSL:JavaScript的XSL在谷歌瀏覽器
function loadXMLDoc(fname)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
try {
xmlDoc.async=false;
xmlDoc.load(fname);
return(xmlDoc);
}
catch(e)
{
try //Google Chrome
{
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET",file,false);
xmlhttp.send(null);
xmlDoc = xmlhttp.responseXML.documentElement;
return(xmlDoc);
}
catch(e)
{
error=e.message;
}
}
}
function displayResult()
{
xml=loadXMLDoc("report.xml");
xsl=loadXMLDoc("report.xsl");
// code for IE
if (window.ActiveXObject)
{
ex=xml.transformNode(xsl);
document.getElementById("example").innerHTML=ex;
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
{
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById("example").appendChild(resultDocument);
}
}
它可以找到IE和Firefox,但鉻是不能在該行:
document.getElementById("example").appendChild(resultDocument);
感謝您的幫助
謝謝,我奮鬥了整整一個早上尋找這個 – Juan 2013-04-26 15:12:18