[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

[Summary] Three ways to express in XPath that there ar

Subject: [Summary] Three ways to express in XPath that there are no duplicates in a list of items
From: "Costello, Roger L." <costello@xxxxxxxxx>
Date: Fri, 2 Nov 2012 09:15:33 +0000
 [Summary] Three ways to express in XPath that there ar
Hi Folks,

Thanks David, Dimitre, and Michael for your excellent feedback.

Let's recap the 3 ways to implement using XPath a boolean test that there are
no duplicates in a list of items.

Problem: Write an XPath expression that returns true if there are no duplicate
websites in the following list, false otherwise:

    <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's how to implement it in XPath 1.0 and in XPath 2.0.

XPath 1.0:

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

XPath 2.0:

	empty(Websites/*[index-of(../*,.)[2]])
	count(Websites/*) = count(distinct-values(Websites/*))

The preferred XPath is the last one because it has the best performance. The
first two take on the order of n-squared time (where n is the number of
websites in the list) whereas the last XPath expression takes on the order of
n log n time.

/Roger

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.