views:

563

answers:

2

Hi, I'm using the following javascript code to display xml/xsl:

function loadXMLDoc(fname)
{
  var xmlDoc;
  // code for IE
  if (window.ActiveXObject)
  {
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  }
  // code for Mozilla, Firefox, Opera, etc.
  else if (document.implementation
  && document.implementation.createDocument)
  {
    xmlDoc=document.implementation.createDocument("","",null);
   }
  else
  {
    alert('Your browser cannot handle this script');
  }
  try {
    xmlDoc.async=false;
    xmlDoc.load(fname);
    return(xmlDoc);
    }
 catch(e)
 {
  try //Google Chrome
  {
   var xmlhttp = new window.XMLHttpRequest();
   xmlhttp.open("GET",file,false);
   xmlhttp.send(null);
   xmlDoc = xmlhttp.responseXML.documentElement;
   return(xmlDoc);
  }
  catch(e)
  {
   error=e.message;
  }
 }
}

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

It works find for IE and Firefox but chrome is fail in the line:

document.getElementById("example").appendChild(resultDocument);

Thank you for you help

+1  A: 

Google Chrome currently has limited support for XSL. If your XSL refers to any external resources (document() function, xsl:import, xsl:include or external entities), the XSL will run but the result will either be empty or invalid.

If that's not the cause of your problem, the issue can be different: resultDocument and document do not share the same root. Try to use importNode or a similar technique. If that fails and you're certain that resultDocument has valid contents, transform it to a string, add a node manually, and set innerHTML of the new node to the string. I know, it's ugly, but until Chrome becomes mature we'll need some workarounds...

Abel
A: 

Hi,

Anyone got answer for this?

unid
This is not an answer to the question. If you like the original question, give it an up vote rather than tacking a non-answer to the end.
Brad