Created attachment 301721 [details] [diff] [review] Fix for problem - get the  node from xpath If you have a scenario like this: <div class="vcard" id="outer_vcard"> <div class="vcard" id="middle_vcard"> <div class="vcard" id="inner_vcard"> <span class="fn">Inner User</span> </div> <span class="fn">Middle User</span> </div> <span class="fn">Outer User</span> </div> And you ask the "inner_vcard" what its parent is, it will tell you "outer_vcard" instead of "middle_vcard" Fix is to be more explicit in what node I get from the XPath testcase is attached as well. Note testcase has some rework of the original microformats testcase to make it easier to add new tests.
This isn't right either. There still seem to be cases where I get a different ancestor. Jonas: What is the correct xpath for "get my immediate ancestor that has a certain classname? Thanks!
Comment on attachment 301721 [details] [diff] [review] Fix for problem - get the  node from xpath Actually I'm doing this wrong. Because I'm enumerating through the list first, I find the first parent that corresponds to the earliest microformat. What I need to do is find the first parent that has any of my microformat class names. Solution coming.
./ancestor::*[class='foo'] Should return the innermost ancestor with a given class. So in the example above ./ancestor::*[class='vcard'] should yield the 'inner_vcard' node if the context node is the span. If you want "the innermost ancestor but only if it has a certain class" the expression would be ./ancestor::*[class='vcard']
Created attachment 301797 [details] [diff] [review] Rewrite of getparent This is a rewrite of getparent to construct one xpath to do what we need. It also has full unit test with all permutations.
Status: NEW → RESOLVED
Last Resolved: 11 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.