2015-05-19 80 views
0

加載XML和XSLT無法在IE11中轉換它之後。
同時改造我越來越Object doesn't support property or method transformNode將內聯XML和內聯XSL轉換爲XHTML

<!DOCTYPE html> 
<html> 
<head> 
<title>XML Data Block Demo</title> 
<script id="GUI" type="application/xml"> 
<GUI> 
    <option> 
    <name>My Inbox</name> 
    </option> 
    <option> 
    <name>My Home</name> 
    </option> 
</GUI> 
</script> 

<script id="GUIxsl" type="application/xml"> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="/"> 

    <h2>GUI</h2> 
    <table border="1"> 
     <tr bgcolor="#9acd32"> 
     <th style="text-align:left">Option</th> 
     </tr> 
     <xsl:for-each select="GUI/option"> 
     <tr> 
     <td><xsl:value-of select="name"/></td> 
     </tr> 
     </xsl:for-each> 
    </table> 
    </xsl:template> 
</xsl:stylesheet> 
</script> 
<script> 
function loadOnPage() { 
    debugger; 
    var xml = document.getElementById("GUI").textContent; 
    var xsl = document.getElementById("GUIxsl").textContent; 
    var parser = new DOMParser(); 
    var docxml = parser.parseFromString(xml, "application/xml"); 
    var docxsl = parser.parseFromString(xsl, "application/xml"); 
    ex = docxml.transformNode(docxsl); 
    document.getElementById("example").innerHTML = ex; 

} 
</script> 
</head> 
<body onload="loadOnPage()";> 
<div id="example" /> 

Demo did not run 
</body> 
</html> 
+0

https://www.w3schools.com/xml/xsl_client.asp示例 – Premraj

回答

1

如果你想使用IE裏面XSLT,那麼你不能使用DOMParser解析XML,您需要使用與new ActiveXObject('Msxml2.DOMDocument.6.0')的MSXML DOM文檔和loadXML方法,我不要以爲試圖把XML或XSLT代碼轉換成HTML不過是一個不錯的主意,樣品http://home.arcor.de/martin.honnen/html/test2015051901.html作品我在IE 11:

function loadOnPage() { 
 
    var xml = document.getElementById("GUI").textContent; 
 
    var xsl = document.getElementById("GUIxsl").textContent; 
 

 

 
    var docxml = new ActiveXObject('Msxml2.DOMDocument.6.0'); 
 
    docxml.loadXML(xml); 
 

 
    var docxsl = new ActiveXObject('Msxml2.DOMDocument.6.0'); 
 
    docxsl.loadXML(xsl); 
 

 
    var htmlFrag = docxml.transformNode(docxsl); 
 
    document.getElementById("example").innerHTML = htmlFrag; 
 

 
} 
 

 
window.onload = loadOnPage;
<!DOCTYPE html> 
 
<html lang="en"> 
 

 
<head> 
 
    <meta charset="UTF-8"> 
 
    <title>Test</title> 
 
    <style> 
 
    </style> 
 
</head> 
 

 
<body> 
 
    <script id="GUI" type="application/xml"> 
 
    <GUI> 
 
     <option> 
 
     <name>My Inbox</name> 
 
     </option> 
 
     <option> 
 
     <name>My Home</name> 
 
     </option> 
 
    </GUI> 
 
    </script> 
 

 
    <script id="GUIxsl" type="application/xml"> 
 
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
 
     <xsl:template match="/"> 
 

 
     <h2>GUI</h2> 
 
     <table border="1"> 
 
      <tr bgcolor="#9acd32"> 
 
      <th style="text-align:left">Option</th> 
 
      </tr> 
 
      <xsl:for-each select="GUI/option"> 
 
      <tr> 
 
       <td> 
 
       <xsl:value-of select="name" /> 
 
       </td> 
 
      </tr> 
 
      </xsl:for-each> 
 
     </table> 
 
     </xsl:template> 
 
    </xsl:stylesheet> 
 
    </script> 
 

 

 
    <div id="example"> 
 

 
    Demo did not run 
 
    </div> 
 

 
</body> 
 

 
</html>

+0

http://home.arcor.de/martin.honnen/html/test2015051901.html擁有發佈的代碼,並且適用於IE 11在Windows 8.1上。我不知道其他方法使用IE在瀏覽器中編寫腳本XSLT。我不認爲你的評論中的其他鏈接涉及腳本'新ActiveXObject('Msxml2.DOMDocument.6.0')'。 –