This code looks for a table that matches
specific criteria:

     XPath.each(@doc, '//table') do |tbl|
       XPath.each(tbl, '//td') do |td|
         # look for matching data

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.

The workaround is to dispense with the
outer loop. Once matching data is found
and keep visiting parents until the
table ancestor is found. (That patch
simplifies the code, actually.)

But if this implementation isn't a bug, it
means that the definition of "context" is
"the entire tree in which the specified
node is found".

In that case, the XPath expression that
asks for "all <td> elements under the
current <table> node" must be something
other than what I coded...

What might that path be, I wonder?