简体   繁体   English

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

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

I have no idea why my code isn't cooperating, with me and my xml.我不知道为什么我的代码不与我和我的 xml 合作。 I'm sorry for giving pics, but when i'm giving code, site is displaying end result, not the code it self, and I have no idea how to change it.我很抱歉提供图片,但是当我提供代码时,网站显示的是最终结果,而不是它自己的代码,我不知道如何更改它。

<?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>

my XML code我的 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>

my XSLT code I really don't know whats wrong, it seems like they are connected to each other in a wrong way, but im still clueless.我的 XSLT 代码我真的不知道出了什么问题,似乎它们以错误的方式相互连接,但我仍然一无所知。

最终结果

This seems to be the usual problem that newer versions of Firefox apply a stricter policy regarding the source of the XML-XSLT combination.这似乎是较新版本的 Firefox 对 XML-XSLT 组合的来源应用更严格的策略的常见问题。 If the XML and XSLT are local files, Firefox will block/ignore the reference to the XSLT.如果 XML 和 XSLT 是本地文件,则 Firefox 将阻止/忽略对 Z139E293A71449EBF2CD6 的引用

The solution is changing one setting in about:config : Set解决方案是更改about:config中的一项设置:设置

privacy.file_unique_origin

to false .false This is the preferred modification, as suggested by @evilpie.正如@evilpie 所建议的,这是首选修改。

This should make your XML display as desired.这应该使您的 XML 显示为所需。 It is discussed here: Firefox 68: local files now treated as cross-origin (1558299) . 这里讨论:Firefox 68:本地文件现在被视为跨域 (1558299)

Firstly: I strongly recommend you use a local http server instead of modifying any preferences in Firefox that make you less secure.首先:我强烈建议您使用本地 http 服务器,而不是修改 Firefox 中的任何使您不那么安全的首选项。

Since around Firefox 68 treats local files as always cross-origin.由于 Firefox 68 左右将本地文件视为始终跨域。 (See "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. (请参阅“本地 HTML 文件可能导致文件被盗” )这可以防止各种安全和隐私问题,例如攻击窃取与下载的 HTML 文件位于同一文件夹中的本地数据。 See also the article "Restrictions on File Urls" .另请参阅文章 “文件 URL 的限制”

Unlike what zx485 recommended you can set privacy.file_unique_origin to false in about:config.与 zx485 推荐的不同,您可以在 about:config 中将privacy.file_unique_origin设置为false

Changing security.fileuri.strict_origin_policy is more insecure and should not be done, because it allows access to all files on your computer.更改security.fileuri.strict_origin_policy不安全,不应该这样做,因为它允许访问您计算机上的所有文件。

Mozilla recommends to run a local server. Mozilla 建议运行本地服务器。 Just install Python 3.x on your machine and serve your working directory with your XML and XSL by launching a batch file from it, with this line:只需在您的机器上安装 Python 3.x 并使用 XML 和 XSL 启动一个批处理文件来为您的工作目录提供服务,使用以下行:

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

With the correct path to your Python, of course.当然,使用 Python 的正确路径。 Firefox will find 'your_bewdiful.xml' in http://localhost:8000/your_bewdiful.xml . Firefox 将在http://localhost:8000/your_bewdiful.xml中找到“your_bewdiful.xml”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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