Re: [xsl] Checking for unique mail adresses

Subject: Re: [xsl] Checking for unique mail adresses
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 18 Jan 2001 13:16:17 +0000
Hi Heiner,

> Actually, it looks a bit better already - I've managed to clean the
> "spam text" from the mails now. All I need to know, still, is to how 
> find out only the unique adresses.

Pretend that you're jumping from 'mail' element to 'mail' element. At
each 'mail' element, you look back across the document. If you can't
see another 'mail' element before this one that has the same value as
the one you're on, then you know you've found a new mail address and
you can write it down.  If you *can* see another 'mail' element with
the same value as this one, then you know you've already written it
down, so you can just ignore it.

Turning this into an XPath.  Jump from mail element to mail element:


look back across the document: is there another mail element that has
the same value as this one?

  . = preceding::mail

If there isn't, then write it down:

  //mail[not(. = preceding::mail)]

So, to cycle over all the unique 'mail' elements, you can use:

<xsl:for-each select="//mail[not(. = preceding::mail)]">

You can also use keys to do this.  Set up a key that, given a mail
address, gives you the 'mail' elements that have that address:

<xsl:key name="addresses" match="mail" use="." />

Now, if the 'mail' element that you're on is the first in the list
returned by the key, then you can write it down: if it isn't, you can
ignore it:

  //mail[generate-id() = generate-id(key('addresses', .)[1])]


  //mail[count(.|key('addresses', .)[1]) = 1]

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread