我是 XSLT 的初学者,对 Muenchian 分组方法感到困惑。这是我的 XML 文档
<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="test.xslt"?>
<catalog>
<cd PurchaseDate="20000101">
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<quantity>20</quantity>
<price>10.90</price>
</cd>
<cd PurchaseDate="20000101">
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<quantity>10</quantity>
<price>9.90</price>
</cd>
<cd PurchaseDate="20000102">
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<quantity>15</quantity>
<price>9.90</price>
</cd>
<cd PurchaseDate="20000101">
<title>Still got the blues</title>
<artist>Gary Moore</artist>
<country>UK</country>
<quantity>5</quantity>
<price>10.20</price>
</cd>
<cd PurchaseDate="20000103">
<title>Eros</title>
<artist>Eros Ramazzotti</artist>
<country>EU</country>
<quantity>6</quantity>
<price>9.90</price>
</cd>
<cd PurchaseDate="20000103">
<title>One night only</title>
<artist>Bee Gees</artist>
<country>UK</country>
<quantity>16</quantity>
<price>10.90</price>
</cd>
<cd PurchaseDate="20000102">
<title>Sylvias Mother</title>
<artist>Dr.Hook</artist>
<country>UK</country>
<quantity>3</quantity>
<price>8.10</price>
</cd>
<cd PurchaseDate="20000101">
<title>Maggie May</title>
<artist>Rod Stewart</artist>
<country>UK</country>
<quantity>8</quantity>
<price>8.50</price>
</cd>
<cd PurchaseDate="20000103">
<title>Romanza</title>
<artist>Andrea Bocelli</artist>
<country>EU</country>
<quantity>30</quantity>
<price>10.80</price>
</cd>
</catalog>
和 XSLT
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" indent="yes" />
<xsl:key name="kByCountry" match="cd" use="country" />
<xsl:output method="html" />
<xsl:template match="catalog">
<html>
<body>
<table border="1">
<xsl:for-each select="cd[count(.|key('kByCountry',country)[1]) = 1]">
<xsl:sort select="country" />
<tr bgcolor="#9acd32">
<td colspan="4">Country:<xsl:value-of select="country" /></td>
</tr>
<tr>
<td>Purchase Date</td>
<td>Quantity</td>
<td>Unit Price</td>
<td>Total</td>
</tr>
<tr>
<td>?date?</td>
<td><xsl:value-of select="quantity" /> </td>
<td><xsl:value-of select="price" /></td>
<td><xsl:value-of select="price*quantity" /></td>
</tr>
<tr>
<td colspan="3" align="right">Sub-total</td>
<td>?how to count subtotal together?</td>
</tr>
</xsl:for-each>
<tr>
<td colspan="3" align="right">Grand-total</td>
<td>?how to count all subtotal together?</td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我的问题是如何列出国家组中的所有购买日期。这样我就可以算出跟随国家的总量了