This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Checking for unique mail adresses
- To: "Heiner de Wendt" <H dot dewendt at systec dot de>
- Subject: Re: [xsl] Checking for unique mail adresses
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Thu, 18 Jan 2001 13:16:17 +0000
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <147E4A31F63@systec.de>
- Reply-To: xsl-list at lists dot mulberrytech dot com
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:
//mail
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)]">
...
</xsl:for-each>
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])]
or:
//mail[count(.|key('addresses', .)[1]) = 1]
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list