我在下面使用Transformation工具测试了XML和XSL。输出不显示任何数据行。任何人都可以帮我找出问题吗?
我使用下面的在线工具。
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 :(得分: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>