当XSL包含Imports时,Internet Explorer 11上的Javascript XSL转换无法正常工作

时间:2018-05-16 11:38:36

标签: javascript internet-explorer xslt

我正在创建一个简单的HTML + javascript页面,允许用户加载特定类型的XML文件,该文件将通过XSL转换转换为HTML。

它在Chrome/Firefox/Edge中工作得很好,但在IE 11上只返回XML文本而没有任何格式化失败。

我怀疑是问题出在主xsl文件的<xsl:import/>中。

我创建了一个向您展示问题的plunker:http://plnkr.co/edit/2HNIOZ

如果你运行i ton Chrome,它会显示一个包含艺术家/歌曲列表的表格。

如果您在Internet Explorer中运行它,它将只显示一堆未格式化的文本。

如果您更改第34行:

xslDoc.load('cdcatalog.xsl');

到:

xslDoc.load('cdcatalog_imported.xsl');

您会看到xml的打印方式与Chrome中的方式相同。

我真的迷失了,因为我不知道如何调试这个问题。

感谢您的帮助:)

PS: 我不是这个工具的专家,所以我无法公开分享我使用的xml和两个xsl文件,所以我将在这里分享:

cdcatalog.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="cdcatalog_imported.xsl"/>
</xsl:stylesheet>

cdcatalog_imported.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html> 
<body>


<h2>My CD Collection</h2>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th style="text-align:left">Title</th>
      <th style="text-align:left">Artist</th>
    </tr>
    <xsl:for-each select="catalog/cd">
    <tr>
      <td><xsl:value-of select="title"/></td>
      <td><xsl:value-of select="artist"/></td>
    </tr>
    </xsl:for-each>
  </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

的catalog.xml

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Hide your heart</title>
    <artist>Bonnie Tyler</artist>
    <country>UK</country>
    <company>CBS Records</company>
    <price>9.90</price>
    <year>1988</year>
  </cd>
  ...
</catalog>

1 个答案:

答案 0 :(得分:0)

我在这里找到了答案:https://msdn.microsoft.com/en-us/library/ms763800(v=vs.85).aspx

我必须启用resolveExternals。

为了解决我的问题,我在第43行之后得到了以下代码:

xslDoc.resolveExternals = true;
相关问题