how to run XSL file using JavaScript / HTML file

Posted by B. Kumar on Stack Overflow See other posts from Stack Overflow or by B. Kumar
Published on 2010-06-10T12:28:51Z Indexed on 2010/06/10 13:12 UTC
Read the original article Hit count: 357

Filed under:

i want to run xsl file using javascript function. I wrote a javascrpt function which is working well with Firefox and Crom but it is not working on Internet Explorer

     function loadXMLDoc(dname)
     {
        if (window.XMLHttpRequest)
          {
              xhttp=new XMLHttpRequest();
          }
        else
          {
              xhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        xhttp.open("GET",dname,false);
        xhttp.send("");
        return xhttp.responseXML;
    }

    function displayResult()
    {
        xml=loadXMLDoc("NewXml.xml");
        xsl=loadXMLDoc("NewFile.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);
          }
    }

Please help my by modifying this code or by another code so that i can work with Internet Explorer.

Thanks

© Stack Overflow or respective owner

Related posts about JavaScript