I was sure there is a more efficient way than this.

I'm cloning too much via XPath and stripping the excess away
afterwards, mostly because I can't think of a better approach (or a
one-line XPath)

for-each looping over operation-data/groupIDs/*/*

want to clone just the current-node, ancestor node and attributes.

<do-clone-xpath
dest-expression="../add[last()][not(operation-data/groupIDs)]"
src-expression="operation-data"/>
<do-strip-xpath
expression="../add[last()]/operation-data/groupIDs/*/*[not(local-name(.)
= local-name($current-node))]"/>