2015-07-13 68 views
0

我遇到了本地存儲的.xml和.xls文件的問題。爲什麼XML不能識別XSL並獲得空白頁?

我的XML文件是:

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="statement.xsl" ?> 
<STATEMENT_3> 

    <SENTENCE> 
     <MENTAL>In my mind there are things I remember and things that are confused </MENTAL> 
    </SENTENCE>  
    <SENTENCE> 
     <MATTERIAL>I saw him near the basketball court </MATTERIAL> 
    </SENTENCE> 
    <SENTENCE> 
     <MATTERIAL> I saw him at my front door </MATTERIAL> 
    </SENTENCE> 

</STATEMENT_3> 

我的.xsl文件如下:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<html xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<body style="font-family:Arial;font-size:13pt;background-color:#E8E09C"> 

<xsl:for-each select="STATEMENT_3/SENTENCE"> 

    <div style="background-color:blue;color:white;padding:4px"> 
     <span style="font-weight:bold"><xsl:value-of select="MENTAL"/> - </span> 
    </div> 

    <div style="background-color:green;color:white;padding:4px"> 
     <span style="font-weight:bold"><xsl:value-of select="MATTERIAL"/> - </span> 
    </div> 

</xls:for-each> 

</body> 
</html> 
</xsl:stylesheet> 

鉻給人空白頁和Firefox說,有一個錯誤:

</xls:for-each> 

我搜索了很多,但找不到任何工作解決方案。

+0

你需要部署和使用瀏覽器測試之前驗證您的XSLT。 XSLTC工具將爲您做到這一點。 'xls:for-each'錯誤會被IDE收集。 – EJP

+0

http://stackoverflow.com/help/someone-answers –

回答

0
</xls:for-each> 

需要是:

</xsl:for-each> 

此外,樣式表必須包含至少一個模板。嘗試是這樣的:

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

<xsl:template match="/"> 
    <html> 
     <body style="font-family:Arial;font-size:13pt;background-color:#E8E09C"> 
      <xsl:for-each select="STATEMENT_3/SENTENCE"> 
       <div style="background-color:blue;color:white;padding:4px"> 
        <span style="font-weight:bold"><xsl:value-of select="MENTAL"/> - </span> 
       </div> 
       <div style="background-color:green;color:white;padding:4px"> 
        <span style="font-weight:bold"><xsl:value-of select="MATTERIAL"/> - </span> 
       </div> 
      </xsl:for-each> 
     </body> 
    </html> 
</xsl:template> 

</xsl:stylesheet> 

在Chrome有關XSLT的問題,請參見(例如): Testing xslt code using your browser

相關問題