Suppose you have an XML like:
<Rows>
<Row Category="Sweet" Value="Chocolate" />
<Row Category="Salty" Value="Potato Chips" />
<Row Category="Salty" Value="Pop Corn" />
<Row Category="Sour" Value="Lemon" />
<Row Category="Sweet" Value="Biscuits" />
<Row Category="Salty" Value="Fries" />
</Rows>
and you want to have these rows grouped by the 'Category
' attribute like:
Salty
--------
Fries
Pop Corn
Potato Chips
Sour
--------
Lemon
Sweet
--------
Biscuits
Chocolate
You can use Muenchian grouping just like the following:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:key name="food-by-Category" match="Row" use="@Category" />
<xsl:template match="Rows">
<xsl:for-each select="Row[count(. | key('food-by-Category', @Category)[1]) = 1]">
<xsl:sort select="@Category" />
<xsl:value-of select="@Category" />
<hr />
<xsl:for-each select="key('food-by-Category', @Category)">
<xsl:sort select="@Value" />
<xsl:value-of select="@Value" />
<br />
</xsl:for-each>
<br />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>