2015-01-10 38 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)。我相信这是解决方案。谢谢! –