replacements.reverse()
for attr in tree2.xpath('//attr'):
    node = replacements.pop()
attr.getparent().replace(attr, copy.deepcopy(node))
print(lxml.etree.tostring(tree2))
поиск/замена содержимого xml