algorithm-nearest-in-parent: Difference between revisions
Jump to navigation
Jump to search
m (rm categories per how-to-play #16, please do not add MediaWiki Categories in general.) |
LimonOrc4t (talk | contribs) (liraccvie) |
||
| Line 1: | Line 1: | ||
taerrelgetra | |||
This algorithm will return all the elements in a DOM that meet the <code>condition_test</code> by checking each node in the parent hierarchy above the <code>start_element</code> on up. Once a result is found at any level of the parent hierarchy, we stop checking. | This algorithm will return all the elements in a DOM that meet the <code>condition_test</code> by checking each node in the parent hierarchy above the <code>start_element</code> on up. Once a result is found at any level of the parent hierarchy, we stop checking. | ||
Revision as of 17:58, 19 December 2008
taerrelgetra
This algorithm will return all the elements in a DOM that meet the condition_test by checking each node in the parent hierarchy above the start_element on up. Once a result is found at any level of the parent hierarchy, we stop checking.
def nearest_in_parent(start_element, condition_test):
p = start_element.parent
while p:
as = []
for c in ordered_depth_first_element_iter(p):
if condition_test(c):
as.append(c)
if as:
return as
p = p.parent
return None