XSLT 样式表不适用于 Firefox 中的 XML。如何解决?

XSLT stylesheet isn't applied to XML in Firefox. How to fix it?

我不知道为什么我的代码不与我和我的 xml 合作。很抱歉提供图片,但是当我提供代码时,网站显示的是最终结果,而不是代码本身,我不知道如何更改它。

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet href="movies.xsl" type="text/xsl" ?>
<collection>
    <movie>
        <title>hasdasd</title>
        <year>1222</year>
        <genre>horror</genre>
    </movie>
    <movie>
        <title>wqw</title>
        <year>1111</year>
        <genre>notporn</genre>
    </movie>
    <movie>
        <title>asdsd</title>
        <year>1444</year>
        <genre>comedy</genre>
    </movie>
</collection>

我的XML代码

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/collection">
      <html>
        <body> <h1>OEIHFWOEFIHEFOI</h1>
        <table border="1">
            <tr>
                <th>title</th>
                <th>Genre</th>
                <th>year</th>
            </tr>
            <xsl:for-each select="movie">
            <tr>
                <td><xsl:value-of select="title" /></td>
                <td><xsl:value-of select="year" /></td>
                <td><xsl:value-of select="genre" /></td>
            </tr>
            </xsl:for-each>
        </table>
        </body>
      </html>
  </xsl:template>
</xsl:stylesheet>

我的 XSLT 代码 我真的不知道怎么了,好像他们之间的联系方式不对,但我还是一头雾水。

这似乎是较新版本的 Firefox 对 XML-XSLT 组合的来源应用了更严格的策略的常见问题。如果 XML 和 XSLT 是本地文件,Firefox 将 block/ignore 引用 XSLT。

解决方案是更改 about:config 中的一项设置:设置

privacy.file_unique_origin

false。正如@evilpie 所建议的那样,这是首选修改。

这应该使您的 XML 显示如愿。正在讨论 here: Firefox 68: local files now treated as cross-origin (1558299)

首先:我强烈建议您使用本地 http 服务器,而不是修改 Firefox 中任何降低您安全性的首选项。

自从 Firefox 68 前后始终将本地文件视为跨源文件。 (参见 "local HTML file can lead to file stealing") This prevents various security and privacy issues such as an attack exfiltrating local data in the same folder as a downloaded HTML file. See also the article "Restrictions on File Urls"

与 zx485 推荐的不同,您可以在 about:config 中将 privacy.file_unique_origin 设置为 false

更改 security.fileuri.strict_origin_policy more 不安全,不应这样做,因为它允许访问您计算机上的 所有 文件.

Mozilla recommends 到 运行 本地服务器。只需在您的计算机上安装 Python 3.x 并通过启动批处理文件来为您 XML 和 XSL 提供工作目录,使用以下行:

cmd.exe /c "\Python38-32\python.exe -m http.server"

当然是 Python 的正确路径。 Firefox 将在 http://localhost:8000/your_bewdiful.xml.

中找到 'your_bewdiful.xml'