R
reed.emmons
I'm trying to load and transform dynamically created xml. It works
great in IE but in Mozilla, it will not transform. I discovered that
when I copy the generated xml into a flat file, it works.
It might be caused by the function that processes the XML was called
before the xml document was completely loaded, though I don't know how
to resolve that.
Any ideas?
<html>
<head>
<script>
function loadXMLDoc(fileName)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject){
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
else if (document.implementation &&
document.implementation.createDocument){
xmlDoc=document.implementation.createDocument("","",null);
}
xmlDoc.async=false;
xmlDoc.load(fileName);
return(xmlDoc);
}
function loadInventory()
{
xml=loadXMLDoc("/inventory/inventoryXML");
xsl=loadXMLDoc("/xsl/inventory.xsl");
// code for IE
if (window.ActiveXObject){
ex=xml.transformNode(xsl);
document.getElementById("inventory").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("inventory").appendChild(resultDocument);
}
}
</script>
</head>
<body onLoad="loadInventory()">
<div id="inventory"></div>
</body>
</html>
great in IE but in Mozilla, it will not transform. I discovered that
when I copy the generated xml into a flat file, it works.
It might be caused by the function that processes the XML was called
before the xml document was completely loaded, though I don't know how
to resolve that.
Any ideas?
<html>
<head>
<script>
function loadXMLDoc(fileName)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject){
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
else if (document.implementation &&
document.implementation.createDocument){
xmlDoc=document.implementation.createDocument("","",null);
}
xmlDoc.async=false;
xmlDoc.load(fileName);
return(xmlDoc);
}
function loadInventory()
{
xml=loadXMLDoc("/inventory/inventoryXML");
xsl=loadXMLDoc("/xsl/inventory.xsl");
// code for IE
if (window.ActiveXObject){
ex=xml.transformNode(xsl);
document.getElementById("inventory").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("inventory").appendChild(resultDocument);
}
}
</script>
</head>
<body onLoad="loadInventory()">
<div id="inventory"></div>
</body>
</html>