Search
| XSLT Grouping and Sorting Example (Muenchian Method) |
|
| Written by Chris Gountanis | |||
|
Sorting distinct groups with XSLT 1.0 is a common issue. When XSLT 2.0 is standardized there will be for-each-group tags available which will replace this example. The code below will show you how to group and sort within each group utilizing an XML data file. The XSL code will group by material then sort by price within each distinct material. To add some additional functionality a choose tag was included in order to style the low quanity values.
The Muenchian Method is a method developed by Steve Muench for performing these functions in a more efficient way using keys. Keys work by assigning a key value to a node and giving you easy access to that node through the key value. If there are lots of nodes that have the same key value, then all those nodes are retrieved when you use that key value. Effectively this means that if you want to group a set of nodes according to a particular property of the node, then you can use keys to group them together.
XSL CODE
XML CODE
CSS CODE
OUTPUT
DOWNLOADSUpdated 02-07-2009: Recently added to the sample code is another Extensible Stylesheet Language (XSL) file that displays the results grouped by material and then by width as well. The standard example above only groups by material while displaying the width as a column for each record. Thanks to Aigars for for sending me this advanced group by code sample. The sample code link above contains both examples.
WORKS SITEDJeni's Grouping Using the Muenchian Method
|
|||
| Last Updated on Saturday, 07 February 2009 13:50 |

