xsl-list
[Top] [All Lists]

Duplicates in multiple, independent lists

2004-02-25 09:42:43
Hi,

I've just been implementing a remove-duplicate template, and had a look
at the suggestions at http://www.dpawson.co.uk/xsl/sect2/N2696.html . The
simplest one for my (reasonably small) data set is at #d3417e34, "Remove
duplicates from a list".

However, after several rewrites weren't working, I noticed that
following:: snarfs the whole of the rest of the document
(http://www.w3schools.com/xpath/xpath_location.asp). Now this is no good
for my data, because there are several sets of lists, separated in the
same file and necessarily treated independently as far as duplication is
concerned. I had to resort to preceding-sibling instead:

<xsl:variable name="no-dupes"
              select="Set/Item/DuplicateBit[
                      not(.=../preceding-sibling::node()/DuplicateBit)]"/>

This traps the context within each Set and prevents duplicate removal
because of later sets. I also used preceding- rather than
following-sibling because it outputs up the first instance of each
duplicate rather than the last, but I suppose that's a matter of taste.

Would it be useful to add this as a caveat to that bit of the FAQ? It's
not as cute as using // and following::, but it might be useful to flag
what (I think) is going on.

Thoughts?

J-P
-- 
Will Self's mobile ring is Smells Like Teen Spirit.

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



<Prev in Thread] Current Thread [Next in Thread>