Hi!
I´m a newbie trying to get the size of groups with XSLT 2.0
What I'm trying to do is get the count of different child elements of a certain node, so I'm grouping them by name.
Given the following sample xml file what I want is a 2 columns table:
Node name | Instances
A | 1
B | 2
C | 1
And what I get with my code is the number of childs, not the size of each gruop.
Node name | Instances
A | 3
B | 2
C | 1
<?xml version="1.0" encoding="ISO-8859-1"?>
<demo>
<A>
<aa1>data1</aa1>
<aa2>data2</aa2>
<aa3>data3</aa3>
</A>
<B>
<bb1>data1</bb1>
<bb2>data1</bb2>
</B>
<B>
<bb1>data1</bb1>
<bb2>data1</bb2>
</B>
<C>
<cc1>data3</cc1>
</C>
</demo>
Here is my xslt code
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="demo">
<html>
<body>
<h2>Group by name</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Node name</th>
<th>Instances</th>
</tr>
<xsl:for-each-group select="*" group-by="name()">
<tr>
<td><xsl:value-of select="name()" /></td>
<!-- this returns the number of childs, not the size of the GROUP -->
<td><xsl:value-of select="count(*)" /></td>
</tr>
</xsl:for-each-group>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Thanks in advance!
Lorena