This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Filtering when grouping by Meunchian Method


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]