Re: [xsl] showing unique element values only

Subject: Re: [xsl] showing unique element values only
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 1 Feb 2001 14:25:13 +0000
Hi Keith,

> I've tried manipulating the order of the ACHFee element with
> <xsl:sort select="feeLevelBottom"/> and so-on. I've used every
> combination of preceding::, following::, following-sibling:: that I
> can come up with, but I still cannot make ONLY UNIQUE cell contents
> be displayed

Here's what you're missing: axes *always* operate on the structure of
the original XML, it don't matter how much you sort or what axes you
try.

At the moment you trying to do (roughly)

  for each ACHfee
    sorted according to feeLevelBottom
       if you haven't already processed something with the same
             feeLevelBottom
          then process this one

Instead, you need to turn it around so that you only select the first
ACHfees with a particular feeLevelBottom in the first place, iterate
over them, and sort *them* according to the feeLevelBottom.

For example:

<xsl:for-each select="//ACHFee
                       [not(feeLevelBottom =
                            preceding::ACHFee/feeLevelBottom)]">
   <xsl:sort select="feeLevelBottom" />
   ...
</xsl:for-each>
                       
You may find it more efficient to use the Muenchian Method to get the
list of fees with unique feeLevelBottoms.  Define a key:

<xsl:key name="fees"
         match="ACHFee"
         use="number(feeLevelBottom)" />

And then select the ACHFees with unique feeLevelBottom values with:

<xsl:for-each
   select="//ACHFee
             [count(.|key('fees', number(feeLevelBottom))[1]) = 1]">
   <xsl:sort select="feeLevelBottom" />
   ...
</xsl:for-each>

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