Paul Kiel's Data Integration Blog
Data integration using Xml / Xslt and anything else...






Subscribe to "Paul Kiel's Data Integration Blog" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog..

  Sunday, May 06, 2007


I'll preface this by saying that I love the new features in XSLT 2.0. The very first features that I used were ones that took care of some problems around grouping of nodes and finding unique ones. The xsl:for-each-group is a life saver. Previously, I'd used tool extensions such as Saxon's saxon:distinct() function to solve the problem. However, depending on the client, I may not have had the choice to use 2.0 or extensions. So I was stuck with trying to find out how to group nodes or find unique nodes using XLST 1.0 features and without proprietary extensions.

Some solutions have been documented, most notably Jeni Tennison who describes the Muenchian Method to grouping nodes. And this is probably the best one.

The problem is that the Muenchian Method requires the use of xsl keys. Some processors (and Jeni notes James Clark's XT is one) don't implement keys. I am a big fan of XT for certain applications and continue to use it on occasion. So I wanted to highligh how I've done grouping, iteration, and uniqueness without keys or extensions and using XSLT 1.0 techniques.

Assumptions:

  • I assume the same scenario as in Jeni's example. Records in a database that contain contacts that need to be sorted. Surnames need to be displayed only once (uniqueness) and matching all forenames (iteration).
  • I am using XSLT 1.0 without any extensions
  • I cannot use keys.
  • I need to iterate through a unique list of nodes (there are likely duplicate values within nodes)
  • There are an unknown number of nodes to iterate through.

While this example is very simple, and could be done with the preceeding or following axes, a complex xml may cause the XPath to get too confusing to track. This method keeps the XPath simple.

The whole story can be found here.


4:55:07 PM    comment []


Click here to visit the Radio UserLand website. © Copyright 2007 Paul Kiel.
Last update: 9/22/2007; 4:26:20 PM.

May 2007
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Feb   Jun