BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


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


XSLT
max() function in xslt
Re: max() function in xslt
max() function, by msxsl:script
Whitespace-stripping
Padding with XSLT
Preceding-subling XSL
Basic Shapes to Paths with TinyLine
XML to CSV using XSLT
Cross-Browser display of XML/XSL
Cross Reference Lookup in XSLT using XML file as Xref table
Recursion reminds me of Recursion (9 XSLT Recursion examples)
XSLT Sort - output entire xml file with new sort order
Variable Variables
Cross Reference Lookup in XSLT using embedded XML
XTrans 1.0
XML Explorer 2.5
Create an N-Column Table from XML node-set
XSLT Select Option Example
XSLT Date filtering, sorting, comparing, and evaluating
XSLT Template for HTML INPUT Tag


 
 

<< XQuery.NET and XML >>


By Dimitre Novatchev
First Posted 01/04/2003
Times viewed 977

The Magic of xsl:key


Summary Demonstrates the power of using xsl:key and the key() function in the sort of two lists of objects (containers and items-contained) connected with a many-to-many relationship.

From microsoft.public.xsl: "I have a sorting problem. If I have this XML (two lists of items, with entries denoting a many-to-many relationship between them)". The source xml document is in the xml-code section below. "And I want to see it as (Container, sorted alphabetically, with the related items as child elements, sorted alphabetically - but NOT a direct copy of either Containers or Items)" The wanted result is in the xml-code section. The solution is in the XSLT-code section. It demonstrates the power of using xsl:key and the key() function in the sort of two lists of objects (containers and items-contained) connected with a many-to-many relationship. Firstly, the "contents" elements are grouped by the "cid" attribute -- the ID of the container they point to. This is an implementation of the Muenchian method for grouping. Then they are sorted by the container name, again obtained as value of the key() function using the @cid attribute's value. With each such sorted element, a "container element is created that has a text node -- the value of the "containername" child of the corresponding "container" element (using again the key() function) and with "item" elements as children -- the items contained in this container, as specified in the (possibly many) "contents" elements. This is done in a double application of the key() function: key('kItem', key('kContents',@cid)/@iid) Here one of the most powerful features of the key() function is used, that its second argument can be a node-set and in this case the corresponding matching nodes for every node in the node-set argument are generated. Do enjoy, Dimitre Novatchev.

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