def remove_nesting(dom, tag_name):
for node in dom.getElementsByTagName(tag_name):<EOL><INDENT>for ancestor in ancestors(node):<EOL><INDENT>if ancestor is node:<EOL><INDENT>continue<EOL><DEDENT>if ancestor is dom.documentElement:<EOL><INDENT>break<EOL><DEDENT>if ancestor.tagName == tag_name:<EOL><INDENT>unwrap(node)<EOL>break<EOL><DEDENT><DEDENT><DEDENT>
Unwrap items in the node list that have ancestors with the same tag.