data = """<node1>
  <node2 a1="x1"> ... </node2>
  <node2 a1="x2"> ... </node2>
  <node2 a1="x1"> ... </node2>
</node1>
"""
doc = xee.fromstring(data)
for tag in doc.findall('node2'):
    if tag.attrib['a1'] == 'x2':
        doc.remove(tag)
print(xee.tostring(doc))
xml filtering with python