[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Meunchian Method - Grouping with attributes

Subject: Re: Meunchian Method - Grouping with attributes
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Sat, 26 Jan 2002 00:41:51 +0000
technology grouping
Hi Brian,

> I've been trying to set the key as <xsl:key name="domain4tech"
> match="technology/@domain" use="technology"/> but this has proved
> useless. Any suggestions?

I think that the reason you're running into difficulties is because
this is actually a two-level grouping problem. The first level of
grouping is grouping all the technology elements by their value (e.g.
tech1, tech2, tech3). The second level of grouping is only required to
get rid of the duplicates - you need to group the technology elements
for each particular technology by their domain attribute.

In XSLT 2.0 terms, the grouping would look like:

  <xsl:for-each-group select="product/technology"
    <xsl:sort select="." />
    <xsl:value-of select="." />
    <xsl:for-each-group select="current-group()"
      domain = <xsl:value-of select="@domain" />

or, alternatively:

  <xsl:for-each-group select="product/technology"
    <xsl:sort select="." />
    <xsl:value-of select="." />
    <xsl:for-each select="distinct-values(current-group()/@domain)">
      domain = <xsl:value-of select="@domain" />

That's probably not much use to you (unless you're using Saxon 7.0),
but it does help see the overall structure of what we're doing.

To do two levels of grouping with keys, you need two keys - one for
the first level, one for the second level. The first level key is easy
- you're grouping technology elements by their value:

<xsl:key name="tech" match="technology" use="." />

The second level is a little harder, because you need to index the
technology elements by *both* their technology and their domain. You
can create a key to do this by concatenating the two values by which
you want to group together, as follows:

<xsl:key name="tech-by-domain" match="technology"
         use="concat(., '+', @domain)" />

Then you need the old Muenchian trick to get the unique values, and
Bob's your uncle:

  <xsl:for-each select="product/technology
                          [generate-id() =
                           generate-id(key('tech', .)[1])]">
    <xsl:sort select="." />
    <xsl:value-of select="." />
      select="key('tech', .)
                [generate-id() =
                                 concat(., '+', @domain))[1])]">
      domain = <xsl:value-of select="@domain" />



Jeni Tennison

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.