|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: XSLT 2.0 multi-level grouping challenge/problem
I did something like this recently. I tested this with your xml (which
needed a little fixing).
<xsl:transform version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/donors">
<xsl:variable name="DONORS" >
<DONORS>
<xsl:for-each-group select="donor" group-by="state" >
<state name="{current-grouping-key()}" >
<xsl:for-each-group select="current-group()" group-by="city"
>
<city name="{current-grouping-key()}" >
<xsl:for-each-group select="current-group()"
group-by="organ">
<organ name="{current-grouping-key()}"><xsl:value-of
select="count(current-group())" /></organ>
</xsl:for-each-group>
</city>
</xsl:for-each-group>
</state>
</xsl:for-each-group>
</DONORS>
</xsl:variable>
<xsl:apply-templates select="$DONORS" />
</xsl:template>
<xsl:template match="DONORS" >
<table border="1">
<tr>
<th>State</th>
<th>City</th>
<th>Organ</th>
<th>count</th>
</tr>
<xsl:apply-templates />
</table>
</xsl:template>
<xsl:template match="state" >
<tr>
<td rowspan="{count(city/organ)}" ><xsl:value-of select="@name"
/></td>
<xsl:apply-templates />
</tr>
</xsl:template>
<xsl:template match="city" >
<xsl:choose>
<xsl:when test="position() eq 1" >
<td rowspan="{count(organ)}"><xsl:value-of select="@name"
/></td>
<xsl:apply-templates />
</xsl:when>
<xsl:otherwise>
<tr>
<td rowspan="{count(organ)}"><xsl:value-of select="@name"
/></td>
<xsl:apply-templates />
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="organ" >
<xsl:choose>
<xsl:when test="position() eq 1" >
<td><xsl:value-of select="@name" /></td>
<td><xsl:value-of select="." /></td>
</xsl:when>
<xsl:otherwise>
<tr>
<td><xsl:value-of select="@name" /></td>
<td><xsl:value-of select="." /></td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:transform>
Brad
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








