I have a XML file as following and I want to Group the books based on the published year and count the number of books for each year. sort the result by ascending order.
<body>
<outline text="A">
<outline text="Abelson, Harold" author="Harold Abelson" title="Struktur und Interpretation von Computerprogrammen. Eine Informatik-Einführung" publisher="Springer Verlag" isbn="3540520430" year="1991"/>
<outline text="Abrahams, Paul W." author="Paul W. Abrahams" title="Tex for the Impatient" publisher="Addison-Wesley Pub Co" isbn="0201513757" year="2000"/>
</outline>
<outline text="B">
<outline text="Bach, Fred" author="Fred Bach" title="UNIX Handbuch zur Programmentwicklung" publisher="Hanser Fachbuchverlag" isbn="3446151036"/>
<outline text="Bach, Maurice J." author="Maurice J. Bach" title="Design of the UNIX Operating System" publisher="Prentice Hall PTR" isbn="0132017997" year="1986"/>
</outline>
</body>
Here is the excepted output
<p> Group by Year </p>
<table border="1">
<tr bgcolor="yellow">
<th>Year</th>
<th>Number</th>
</tr>
<tr>
<td>1963</td>
<td>1</td>
</tr>
<tr>
<td>1966</td>
<td>1</td>
</tr>
Here is my code:
<xsl:template match="body">
<xsl:copy>
<table border="1">
<tr bgcolor="Yellow">
<th class="cell"><span> Year </span></th>
<th class="cell"><span> Count </span></th>
</tr>
<xsl:apply-templates select="outline"/>
</table>
</xsl:copy>
</xsl:template>
<xsl:key name="groupbyyear" match="outline" use="@year"/)/>
<xsl:template match="outline/outline">
<tr>
<xsl:sort select="year" order="ascending" />
</tr>
</xsl:template>
</xsl:stylesheet>
I'm not sure how to use the xsl key function and what should I do inside the template after the key function?