1

I am trying to transform XML using XSLT. It Works Perfectly on FF , Chrome , IE upto 10. But in IE-11 its not Working . Here is a Sample code i am using.

function TransformXML(XmlPath, XsltPath) {
    xml = loadXMLDoc(XmlPath);
    xsl = loadXMLDoc(XsltPath);
    // code for IE
    if (window.ActiveXObject || "ActiveXObject" in window){
        ex = xml.transformNode(xsl);
        $('#divId').html(ex);
    }
        // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation && document.implementation.createDocument) {
        //alert("In");
        xsltProcessor = new XSLTProcessor();
        xsltProcessor.importStylesheet(xsl);
        var xmldom = xsltProcessor.transformToDocument(xml);
        var serializer = new XMLSerializer();
        var transformed = serializer.serializeToString(xmldom.documentElement);
        $('#divId').html(transformed);
    }
}
Dhvl Pithva
  • 13
  • 1
  • 5

1 Answers1

1

I guess the problem is in loadXMLDoc(XsltPath), so we need to see the code of that function. IE used to return an MSXML DOM document as responseXML and MSXML supports XSLT with transformNode. Recent IE versions return an IE DOM document as responseXML and don't support XSLT (nor with transformNode nor at all). If you want to use XSLT and load the stylesheet code with XMLHttpRequest then you need e.g.

function loadXMLDoc(url) {
  if (typeof XMLHttpRequest !== 'undefined')
  {
    var xhr = new XMLHttpRequest();
    xhr.open(method, url, false);
    // request MSXML responseXML for IE
    try { xhr.responseType = 'msxml-document'; } catch(e){}
    xhr.send();
    return xhr.responseXML;
  }
  else {
    try {
      var xhr = new ActiveXObject('Msxml2.XMLHTTP.3.0');
      xhr.open('GET', url, false);
      xhr.send();
      return xhr.responseXML;
    }
    catch (e) {
      // handle case that neither XMLHttpRequest nor MSXML is supported
    }
  }
}
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110