嗨,我是 XSL 的新手,我试图输出一个表格,显示客户 ID 和购买的汽车数量,以及根据我的 XML 文件购买超过 1 辆汽车的客户。一个示例输出是:
客户
3
4
汽车数量
3
2
但我现在得到的是:
客户
3
3
3
4
4
9
车数
null
null
null
null
null
null
这是我的 XML 文件。
<cars>
<car>
<carID>
3
</carID>
<mobileNumber>
<areaCode>
00353
</areaCode>
<number>
8723059
</number>
</mobileNumber>
<customerID>
3
</customerID>
<purchaseDate>
<dayPurchased>
6
</dayPurchased>
<monthPurchased>
April
</monthPurchased>
<yearPurchased>
2011
</yearPurchased>
</purchaseDate>
</car>
<car>
<carID>
4
</carID>
<mobileNumber>
<areaCode>
00353
</areaCode>
<number>
8723099
</number>
</mobileNumber>
<customerID>
3
</customerID>
<purchaseDate>
<dayPurchased>
6
</dayPurchased>
<monthPurchased>
April
</monthPurchased>
<yearPurchased>
2011
</yearPurchased>
</purchaseDate>
</car>
<car>
<carID>
5
</carID>
<mobileNumber>
<areaCode>
00353
</areaCode>
<number>
8723777
</number>
</mobileNumber>
<customerID>
3
</customerID>
<purchaseDate>
<dayPurchased>
6
</dayPurchased>
<monthPurchased>
April
</monthPurchased>
<yearPurchased>
2011
</yearPurchased>
</purchaseDate>
</car>
<car>
<carID>
16
</carID>
<mobileNumber>
<areaCode>
00353
</areaCode>
<number>
8721777
</number>
</mobileNumber>
<customerID>
4
</customerID>
<purchaseDate>
<dayPurchased>
6
</dayPurchased>
<monthPurchased>
April
</monthPurchased>
<yearPurchased>
2011
</yearPurchased>
</purchaseDate>
</car>
<car>
<carID>
166
</carID>
<mobileNumber>
<areaCode>
00353
</areaCode>
<number>
8722777
</number>
</mobileNumber>
<customerID>
4
</customerID>
<purchaseDate>
<dayPurchased>
6
</dayPurchased>
<monthPurchased>
April
</monthPurchased>
<yearPurchased>
2011
</yearPurchased>
</purchaseDate>
</car>
<car>
<carID>
169
</carID>
<mobileNumber>
<areaCode>
00353
</areaCode>
<number>
8721787
</number>
</mobileNumber>
<customerID>
9
</customerID>
<purchaseDate>
<dayPurchased>
6
</dayPurchased>
<monthPurchased>
April
</monthPurchased>
<yearPurchased>
2011
</yearPurchased>
</purchaseDate>
</car>
</cars>
这是我的 XSL 文件。
<?xml version="1.0"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html> <head><title>Customers</title></head> <body> <table rules="all">
<thead><tr><th>Customer</th><th>Number of Cars Purchased</th></tr></thead>
<xsl:for-each select="cars/car">
<tr><td> <xsl:apply-templates select="customerID"/> </td>
</xsl:for-each>
</table></body></html>
</xsl:template>
</xsl:transform>
提前致谢。