Could someone who’s skilled in javascript please help me solve this.
I’m trying to get the W3C tutorial XSLT - On the Client to work in the Google Chrome Browser.
It works fine in IE and FF but in Chrome it doesn’t work at all, no error message even.
I read some things about XMLdocument.load isn’t supported in Chrome so I’m guessing it’s something to do with that but I have no idea how to implement a fix.
I read this on a different forum. I’ve tried implementing it in the code but cannot get it to work.
Try replacing:
var xmlDoc = document.implementation.createDocument("", " ", null);
xmlDoc.async = false;
xmlDoc.load(xmlsrc);
With:
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET", xmlsrc, false);
xmlhttp.send(null);
var xmlDoc = xmlhttp.responseXML.documentElement;
Here is the code I’m trying to get to work:
<html>
<head>
<script>
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');
}
xmlDoc.async=false;
xmlDoc.load(fname);
return(xmlDoc);
}
function displayResult()
{
xml=loadXMLDoc("cdcatalog.xml");
xsl=loadXMLDoc("cdcatalog.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);
}
}
</script>
</head>
<body id="example" onLoad="displayResult()">
</body>
</html>
Thanks for any help!!