I am struggling with a tail problem. Here is the example;
<sp> <speaker>Rainoldes.</speaker> <p>You may learne the reason hereof in your <hi>Por‑tesse,</hi> reformed lately by the Pope. In your olde <note n="c" place="margin"> <hi>Portiforium seu breuiarium, ad vsum ecclesiae Sarum: in festo S. Thomae Can‑••ariensis.</hi> </note> <hi>Portesse</hi> there was this prayer to the Popes martyr, <hi>S. Thomas Bec‑ket of Canterbury:</hi> <q> <floatingText> <body> <div type="version"> <l>Christe Iesu,</l> <l>per Thomae vulnera,</l> <l>Quae nos ligant.</l> <l>relaxa scelera.</l> </div> <div type="version"> <l>By Thomas woundes,</l> <l>O Christ Iesus,</l> <l>Loose thou the sinnes▪</l> <l>which do binde vs.</l> </div> </body> </floatingText> </q> Or, if you will haue better ryme, with as bad reason: <q> <pb n="480" facs="tcp:15991:239"/> <floatingText> <body> <div type="version"> <l>Tu per Thomae sanguinem</l> <l>quem pro te impendit,</l> <l>Fac nos Christe scandere</l> <l>quo Thomas a•cendit.</l> </div> <div type="version"> <l>By the blood of Thomas</l> <l>which he for thee did spend,</l> <l>Make vs O Christ to clime</l> <l>whether he did a••end.</l> </div> </body> </floatingText> </q> <q> <l>Mary had a little lamb</l> </q> </p> </sp>
In this example (and many others from a larger collection) I want to strip <q> as unnecessary wrappers. In this particular case, I could use strip_tags. But this wouldn't work in cases where q does not wrap a floatingText element. In many cases, it would be simple to do something like
q.addprevious(floatingText) parent = q.getparent() parent.remove(q)
But this code removes the tail of q, which I want to keep. How do I remove the empty q element without removing the tail as well?