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

Re: Filtering when grouping by Meunchian Method

Subject: Re: Filtering when grouping by Meunchian Method
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 4 Dec 2001 12:42:34 +0000
when grouping
Hi Brian,

> Does anyone know how to filter the result set given by sorting with
> the Meunchian method? I would like to filter the following based on
> an attribute of GOVERNING_TECHNOLOGY called GTBookmark.

Ideally you'd be able to set up the key such that it only matched
those GOVERNING_TECHNOLOGY elements whose GTBookmark attribute was
equal to whatever value you're interested in, e.g.:

<xsl:key name="gt" match="GOVERNING_TECHNOLOGY[@GTBookmark = 'foo']"
         use="." />
         
However, it looks as though you're getting the value that you want
GTBookmark to match through a variable of some description, which
means that you can't use it when you set up the key. So instead you
need to define the general key that you have, and then filter the
result of calling the key so that it only includes the
GOVERNING_TECHNOLOGY elements that you're interested in.

When you do the initial grouping, you need something like:

  <xsl:apply-templates
    select="PRODUCT/GOVERNING_TECHNOLOGY
              [generate-id() =
               generate-id(key('gt', .)[@GTBookmark = $variable])]">
    <xsl:sort select="." />
  </xsl:apply-templates>

For greater efficiency you could filter the GOVERNING_TECHNOLOGY
elements that you check while creating the unique list as well:

  <xsl:apply-templates
    select="PRODUCT/GOVERNING_TECHNOLOGY[@GTBookmark = $variable]
              [generate-id() =
               generate-id(key('gt', .)[@GTBookmark = $variable])]">
    <xsl:sort select="." />
  </xsl:apply-templates>

[Note that I'm here sorting by the value of the node rather than going
through the rigamarole of getting the value of the first node returned
by the key for its particular value, which will always be exactly the
same thing, since the GOVERNING_TECHNOLOGY elements that you're
sorting are always the first returned by the key.]
  
The reason that filtering the GOVERNING_TECHNOLOGY elements that
you're checking doesn't work on its own is that you're essentially
checking, for each of those GOVERNING_TECHNOLOGY elements, whether
they're the same as the first one returned by the key, but the key
could return GOVERNING_TECHNOLOGY elements with different GTBookmark
values, some of which might appear before the GOVERNING_TECHNOLOGYs
that you're interested in, in which case there's no chance of them
being the same node.
  
You'll also have to filter the result of the key when you call the key
to get the individual items of the group, otherwise you'll end up with
all the GOVERNING_TECHNOLOGY elements with the same value, no matter
what their GTBookmark is.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.