Displaying XML with JavaScript

Discussion in 'XML' started by clocke, Feb 16, 2010.

  1. clocke

    clocke

    Joined:
    Mar 25, 2009
    Messages:
    1
    Likes Received:
    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.
     
    clocke, Feb 16, 2010
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.