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

Re: Efficient XPath 2.0 expression to return each <row

Subject: Re: Efficient XPath 2.0 expression to return each <row> element for which there are other <row> elements having the same navaid?
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 13 Dec 2018 18:18:20 -0000
Re:  Efficient XPath 2.0 expression to return each <row
On Thu, Dec 13, 2018 at 06:07:35PM -0000, Costello, Roger L. costello@xxxxxxxxx scripsit:
> I have a large XML document containing data about airports around the world:
[...]
> I want an XPath 2.0 expression to return each <row> element for which there are other <row> elements having the same navaid. For the above example, I want the XPath expression to return the first and third <row> elements.
> 
> Here is one way to do it:
> 
> //row[navaid = (preceding-sibling::row/navaid, following-sibling::row/navaid)]
> 
> Eek! That is horribly inefficient. I ran that XPath expression on my XML document and it took a long time to finish.
> 
> Is there an efficient XPath 2.0 expression to solve this problem?

Probably not.

What you want to answer is "who are the others like me?" and this
compels you to either create some kind of mapping (XQuery maps are just
the thing; so are XSLT keys (or maps!)) so you can just ask the mapping,
or it compels you to stand on each node in turn and check all the
previous and following nodes for similarity, which is going to be
n^yikes in efficiency terms.

But the essential point is that you can't efficiently answer the
question relative to any single context node; if you try to answer it
from the document element, you suddenly need data structures XPath
hasn't got, and if you try to answer it from each row, you have to
re-commpute things.

-- Graydon

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.