Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Getting nested-group item counts [Thread Next] Re: Getting nested-group item countsTo: NULL Date: 8/8/2009 1:42:00 PM
Chris Gannon wrote:
> I've got some xslt that's performing nested grouping and everything is
> almost right with the world.
>
> I'm grouping first on Location, then on Category.
>
> What I would like to do is display the item count next to each
> Category for that Location but I keep getting the total count of all
> items with the same Category name...
>
> What I'd like to see is...
> Location: East Category: Meetings [4]
> East meeting item 1
> East meeting item 2
> East meeting item 3
> East meeting item 4
>
> Location: West Category: Meetings [2]
> West meeting item 1
> West meeting item 2
>
> What I'm getting is
> Location: East Category: Meetings [6]
> East meeting item 1
> East meeting item 2
> East meeting item 3
> East meeting item 4
>
> Location: West Category: Meetings [6]
> West meeting item 1
> West meeting item 2
Here is a sample stylesheet, once you have used two keys where the
second key concatenates the Location and Category values you can simply
count the number of items the key function returns:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:key name="k1" match="Row" use="@Location"/>
<xsl:key name="k2" match="Row" use="concat(@Location, '|', @Category)"/>
<xsl:template match="/">
<xsl:for-each select="dsQueryResponse/Rows/Row[generate-id() =
generate-id(key('k1', @Location)[1])]">
<xsl:for-each select="key('k1', @Location)[generate-id() =
generate-id(key('k2', concat(@Location, '|', @Category))[1])]">
<xsl:variable name="group" select="key('k2', concat(@Location,
'|', @Category))"/>
<xsl:value-of select="concat('Location: ', @Location, '
Category: ', @Category, ' [', count($group), '] ')"/>
<xsl:for-each select="$group">
<xsl:value-of select="concat('	', @Item, ' ')"/>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
--
Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
