xsl-list
[Top] [All Lists]

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

2012-11-01 16:26:24
As David says: there's the "//" difference, and there's the fact that index-of() has slightly different comparison semantics - "=" throws an error if you compare a number to a string, index-of() effectively returns false.

Both are O(n^2), and are therefore poor solutions given that there's a perfectly good O(n log n) solution, namely

count(Websites/*) = count(distinct-values(Websites/*))

Michael Kay
Saxonica

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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--