为什么这个XML文件中不会显示任何内容? [重复](Why does this XML file

2019-09-17 07:03发布

可能重复:
我怎样才能使铬XSLT的工作?

我有这样的XML文件:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="catalog.xsl"?>

<catalog>
    <album>
        <title>Exodus</title>
        <artist>Bob Marley</artist>
        <country>Jamaica</country>
        <price>19,99</price>
    </album>
    <album>
        <title>Black Album</title>
        <artist>Metallica</artist>
        <country>USA</country>
        <price>20,00</price>
    </album>
    <album>
        <title>Nevermind</title>
        <artist>Nirvana</artist>
        <country>USA</country>
        <price>22,00</price>
    </album>
</catalog>

可链接到这个XSL文件:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="/">
        <html>
            <body>
                <h2>My Catalog</h2>
                <table border="1">
                    <tr bgcolor="#9ACD32">
                        <th>Title</th>
                        <th>Artist</th>
                    </tr>
                    <xsl:for-each select="catalog/album">
                        <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>

当我在浏览器中打开XML文件,我没有看到显示任何东西。 自从我的指示一教程复制,我不知道哪里出了问题在这里。 你们有什么可能会导致缺乏显示器方面的任何线索?

Answer 1:

根据浏览器的XSLT限制你使用你可能会看到什么。

我测试在本地使用Chrome 19.0.1084.46和Firefox 3.6.22您的文件。

在Firefox中,我可以没有任何问题查看,但在Chrome中我什么也没看见。

当我在Chrome中打开控制台选项卡开发工具也显示此消息:

从框架///temp/web/catalog.xsl与URL文件:不安全试图加载URL文件///temp/web/catalog.xml。 域,协议和端口必须匹配。

于是,我开始了我的Tomcat并部署了2个文件,当我从Chrome中就万事大吉了访问XML,它显示一切正常。

我猜你正在使用的文件访问它:///这是有关这个问题的Bug 397894



文章来源: Why does this XML file not display anything? [duplicate]