Displaying XML with JavaScript

Joined
Mar 25, 2009
Messages
1
Reaction score
0
On the following HTML page, the JavaScript writes the XML perfectly using the document.write method so that it appears as if the XML page had been opened in the browser.

<html>
<head>
<title></title>
<script language="javascript" type="text/javascript">
function displayResult() {
xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.async = false;
xmldoc.load("XMLFile.xml");

xsldoc = new ActiveXObject("Microsoft.XMLDOM");
xsldoc.async = false;
xsldoc.load("defaultss.xslt");
//document.getElementById("example").innerHTML = xmldoc.transformNode(xsldoc);
document.write(xmldoc.transformNode(xsldoc));
}
</script>
</head>
<body onload="displayResult()">
<div id="example"></div>
</body>
</html>

However, if I uncomment the line prior to the document.write line, and comment that line, so that the XML appears within the div, none of the styles from the defaultss.xslt page are applied. Can somebody please tell me how to make the XML appear with all of the styles applied within the div?

Message length restriction prevents me from posting the defaultss.xslt code, but, as I said, it works perfectly with document.write, so I assume that I am missing something amazingly simple that is beyond my negligible knowledge of XML.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top