Adding attributes with ascending integer values to XML elements only if they have children

I want to add the add attribute ‘id="number"’ to an existing file. id attributes should only be added if the element has at least one child. So right now my XML file looks like this: <Invoice> <Fussteil> <Summen> <QF/> <UstSatz>21.00</UstSatz> <Betrag> <Bezeichnung>Steuerbetrag</Bezeichnung> <QF>124</QF> <Wert>8.8</Wert> </Betrag> </Summen> <Betrag> <Bezeichnung>Gesamtbetrag alle Zu/Abschläge</Bezeichnung> <QF>131</QF> <Wert>12.5</Wert> </Betrag> <Betrag/> <Betrag>… Read More Adding attributes with ascending integer values to XML elements only if they have children