BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


Add/Edit your code items
Search the code library
Browse for the code library


XSLT
Comparing Strings in XSLT for greater/less
How to do a search and replace in XSLT
How to work with more than one xml document in your XSLT transformation
Sorting (advanced) of dynamically constructed strings
In case you need a ""break"" from an xsl:for-each loop
Format XML/XSL for Documentation
Find all xsl:variables that are in scope?
Binary Search in XSLT
Get the newest 5 articles out of hundreds -- a super efficient sort in XSLT
Dynamically change the encoding of your XSLT stylesheet
Identifying an attribute or a namespace node
Build a XPath expression for a node
Avoiding an XSLT Processor crash due to deep recursive processing
Conditional generation of a string in a single XPath expression
Re: Re: ABS function implemented as a single XPath expression
Re: ABS function implemented as a single XPath expression
ABS function implemented as a single XPath expression
XML to HTML text editor
Dynamically Selecting Which Element To Sort On Using Parameters
Avoid NaN in XPath sum() function


 
 

<< XQuery.NET and XML >>


By Dimitre Novatchev
First Posted 12/03/2007
Times viewed 561

Grouping using xsl:key and the key() function -- the Muenchian method


Summary Using the Muenchian method, the following snippet describes how to group your data, returning a distinct, unique list of data.

In many XSLT applications it is necessary to output only a single element that has a specific value (e.g. for an attribute, of a child, of a combination of attributes, of a combination of children, ..., etc.)

This method uses the fact that key(keyName, value) returns all the nodes, which are covered by the @match pattern of the xsl:key element with name=keyName, and for which the expression defined by the @use attribute of this xsl:key evaluates to value.

If we take only one (the first) node of each such group, then we have selected a subset of nodes, each having different value for the expression as defined in xsl:key.

This method was first proposed by Steve Muench and is known as the Muenchian method.

In the example below, all person elements are output, the name of which start with a new letter. The following names will be output:

Adrian
Hayley
Ian

Additional information

Further additional information


Rate this article on a scale of 1 to 10 (0 votes, average 0)

Your vote :  

<< XQuery.NET and XML >>





Leave a comment for this article
Your name
Your email (optional)
Your comment
Optional: Upload an attachment
Enter the code shown:

 
 

    Email TopXML