2012-05-16 143 views
2

可能重复:
How can I make XSLT work in chrome?这个XML文件为什么不显示任何内容?

我有这个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> 

w ^当我在浏览器中打开XML文件时,我没有看到任何显示内容。由于我按照指示复制了教程,所以我不确定这里出了什么问题。你有什么线索可能导致缺乏显示?

+0

它实际上是为我工作。浏览器问题? – keyser

+0

@Keyser:我在Chrome中试过。你在尝试这个? – stanigator

+0

也为我工作。 – Drona

回答

3

根据您使用的浏览器的XSLT约束,您可能看不到任何东西。

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

在Firefox中,我可以毫无问题地查看它,但在Chrome中我什么都看不到。

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

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

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

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

相关问题