[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Are these equivalent XPath expressions for determining that there are no duplicates in a list of items?


Subject: Re: [xsl] Are these equivalent XPath expressions for determining that there are no duplicates in a list of items?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 01 Nov 2012 13:15:54 +0000

On 01/11/2012 13:01, Costello, Roger L. wrote:
Hi Folks,

Are there no duplicate websites in this list:

<Websites> <Website id="Amazon"> http://www.amazon.com </Website>
<Website id="Apple"> http://www.apple.com </Website> <Website
id="Ebay"> http://www.ebay.com </Website> <Website id="Google">
http://www.google.com </Website> <Website id="Microsoft">
http://www.microsoft.com </Website> <Website id="VirginAtlantic">
http://www.virgin-atlantic.com </Website> </Websites>

Here is an XPath 2.0 expression to answer that question (thanks to
Dimitre):

empty(Websites/*[index-of(../*,.)[2]])

Here is an XPath 1.0 expression to answer that question:

not(//Websites/*[. = preceding-sibling::*])

Are there any situations where those two XPath expressions differ in
their answer?

/Roger


both would be rather inefficient in XSLT where you could use keys or
for-each-group. They are different mainly because the second one uses
//at the front (which isn't related to the duplicate removal. You should
use // on either both or neither of them depending what you want). The other difference is that index-of uses eq equality whereas you have used = not eq in the second form That probably only makes a difference in this context if there is some weird schema typing involved.


David


Current Thread
Keywords