2012-05-16 64 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

相關問題