From: Eric Armstrong Date: 2006-08-04T08:05:25+09:00 Subject: Re: REXML XPath: bug or misunderstanding? Paul Battley wrote: > On 02/08/06, Robert Klemme wrote: >> Eric Armstrong wrote: >> > ... >> > According to the XPath doc, the first argument >> > is the "context" element. >> > >> > So what /should/ happen is that search >> > for td elements occurs in the subtree >> > rooted at the tbl element, using the >> > //td path --which I take to mean "anywhere >> > within the context". >> > >> > But what actually happens is that the >> > search for td elements occurs in the >> > entire document, so the code above returns >> > the first table, regardless of where the >> > matching data is found. >> >> That sounds like a bug. > > That's what I thought when I first encountered it, but after looking > into it in more detail I concluded that it follows the specification. > The receiving element does indeed provide context, but using // > overrides it: // means the root node or any of its descendants. > Matches my experience. > ...could have used: XPath.each(tbl, 'descendant::td') > Interesting construct. I guess that's a good way to go, and I guess that matches the Xpath spec...but I'm highly dubious about a spec that defines "context" as something it can simply ignore. Makes little sense, from my current perspective.