2015-01-10 86 views
1

我使用轉換工具在XML和XSL下面進行了測試。輸出不顯示任何數據行。任何人都可以幫我找出問題嗎?XSLT轉換不顯示任何數據

我用下面的在線工具。

http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog_ex3

XML

<?xml version="1.0" encoding="UTF-8"?> 
<vehicles xmlns="http://www.w3schools.com" 
    xmlns:xsi="http://www.w3schools.comm/2001/XMLSchema-instance"> 
     <vehicle> 
      <make>Toyota</make> 
      <model>Prius</model> 
      <color>White</color> 
      <yearofmanufacture>2013</yearofmanufacture> 
      <engine>1.5CC</engine> 
      <doors>5</doors> 
     </vehicle>  
</vehicles> 

XSL

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/"> 
     <html> 
      <body> 
       <h2>Car Sale - Stock List</h2> 
       <table border="1"> 
        <tr bgcolor="#9acd32"> 
         <th>Make</th> 
        </tr> 
        <xsl:for-each select="vehicles/vehicle"> 
         <tr> 
          <td> 
           <xsl:value-of select="make" /> 
          </td> 
         </tr> 
        </xsl:for-each> 
       </table> 
      </body> 
     </html> 
    </xsl:template> 
</xsl:stylesheet> 

輸出:

汽車銷售 - 庫存清單

+0

可能重複[XSLT從文件比不同的WebService(HTTP ://sackoverflow.com/questions/18190640/xslt-from-file-different-than-webservice) – JLRishe

回答

3

是的,問題是,你不使用你的XPath命名空間,你應該做的:

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:ws="http://www.w3schools.com"> 
    <!-- ^^^---- here --> 
    <xsl:template match="/"> 
     <html> 
      <body> 
       <h2>Car Sale - Stock List</h2> 
       <table border="1"> 
        <tr bgcolor="#9acd32"> 
         <th>Make</th> 
        </tr> 
        <!-- here         --> 
        <xsl:for-each select="ws:vehicles/ws:vehicle"> 
         <tr> 
          <td> 
           <!-- and here     --> 
           <xsl:value-of select="ws:make" /> 
          </td> 
         </tr> 
        </xsl:for-each> 
       </table> 
      </body> 
     </html> 
    </xsl:template> 
</xsl:stylesheet> 
+0

非常感謝。它現在有效。 –

+0

@JSIK如果它解決了您的問題,請不要忘記[**接受此答案**](http://stackoverflow.com/help/someone-answers)。我相信這是解決方案。謝謝! –