Hi, On Montag, 13. April 2026 22:14:09 CEST Martin Mueller wrote: > Many thanks for your helpful response. I did indeed leave out the critical > detail of the number of hi children. > > This was the code that used strip_tags > > > def process_tree(tree,filename, item): > for text in tree.iter(tei + 'text'): > for hi in text.iter(tei + 'hi'): > if len(hi) == 1 : > etree.strip_tags(text, tei+ 'hi') > > This ignore the "len(hi) == 1" condition and drops all hi elements but > leaves the children in place. It would be nice if there were a way of > telling strip_tags only to remove hi elements that meet some condition. > That said, it's easy enough to use the addnext() method and loop through > the hi element in reverse order. > > The URL you sent me got wrapped in some security garbage and was missing > something at the end. I couldn't open it, but it looked like a useful > source. Could you send it again?
That was actually a mailing list link to a previous conversation of yours on the lxml mailing list from March 7th 2026: https://mail.python.org/archives/list/[email protected]/message/ 2F7ZICTGEBIQEHRUOSGUE7DZQ7OAA4AZ/ Be aware that that my mailer may put in an unwanted line break so you might need to make sure you copy the full link to the browser. It's a nice tip by Jens Tröger, quoting him here for convenience: " Are you familiar with XPath? I think for w in tree.xpath("//hi[count(w) < 4]/w"): w.attrib["rend"] = "hi" # Add the @rend attribute to the <w> children. hi = w.getparent() # Get the <hi> parent. hi.tag = "hi-remove-me" # Change the <hi> element’s tag so we can find it. etree.strip_tags(tree, "hi-remove-me") # Not sure about the ns here. should get you started… 🤔 Jens " Best, Holger _______________________________________________ lxml - The Python XML Toolkit mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/lxml.python.org Member address: [email protected]
