[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
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|