简体   繁体   中英

XSLT works with Opera, Safari and Chrome but not with Firefox 13 and Internet Explorer 9

I've some problems with Internet Explorer 9 and Firefox 13. I'm building a Web Interface using HTML, XSL and XML, it works fine with Chrome, Opera and Safari without any changing, but it doesn't work with Firefox 13 and Internet Explorer 9. With Firefox there are some pages (not all) that can't load XML values, in Internet Explorer I'm not able to load css for html pages which use XSLT, but I can load all the parameters correctly.

Above you can find an example of a page that does not work (HTML,XML,XSL)

HTML

<html>
<head>
<script>
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
  {
  xhttp=new XMLHttpRequest();
  }
else
  {
  xhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xhttp.open("GET",dname+"?id="+Math.random(),false);
xhttp.send("");
return xhttp.responseXML;
}

function displayResult()
{
xml=loadXMLDoc("sensorParameters.xml");
xsl=loadXMLDoc("sensorParameters.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);
  }
}
</script>
</head>
<body onload="displayResult()">
<div id="example" />
</body>
<head>
<meta http-equiv="cache-control" content="no-cache">
</head>
</html>

XSL

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
    <head>
          <title>Interface</title>
          <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body>
    ...
    (It continues, but it is not important...)
    </body>
</html>
</xsl:template>
</xsl:stylesheet>

XML

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="sensorParameters.xsl"?>
<section1>
<section2>
          ......... some data
</section2>
<section3>
          ......... some data
</section3>
          .........
</section1>

Any help will be appreciated.

Marco

As for the IE problem, I think one probable cause of the problem is your approach of using XSLT to create a complete HTML document with html root element, head section with link to a stylesheet, but then to try to include the XSLT result into a div element (where IE then probably ignores the link ). To fix that you would need to change the approach and make sure you add link elements created by XSLT to the head of the HTML document you insert the XSLT transformation result into.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM