Just in case they're useful, I'll share some thoughts on managing ID attribute settings on XML elements through use of cut/copy/paste callbacks which we've been doing for years here at SAS. The points made below present the highlights. Of course, the details are much more involved. Most of our callback support is implemented within ACL code. A portion, that which sets new ID attribute values within content to be pasted, is implemented in java using the AOM.
Our cut callback is used to detect when we do not need to set new ID attribute values for a subsequent paste:
We have an override implementation of the normal undo operation where we monitor for an undo operation so if, on a subsequent paste, we detect that an undo occurred while a fresh cut was in the paste buffer, we can prompt the user to determine what to do and thereby avoid the next paste possibly storing duplicate ID attribute values.
Our "notify" callback is used to monitor for an activate window operation occurring which would indicate the user may have copied something else into the paste buffer through another application. So if one occurs while a fresh cut is in the paste buffer, we can verify whether the paste buffer contents have changed and if so reset the fresh cut indicator and thereby avoid the next paste possibly storing duplicate ID attribute values.
Our copy callback is used to reset the global state indicators relating to a fresh cut being in the paste buffer.
Our paste callback is used to set new ID attribute values within the pasted content if it is needed:
In Reply to Brian Jensen:
Maybe I missed something from the discussion, but it seemed like nobody
mentioned the fact that we do have access to the documents in named
paste buffers using the acl function buffer_doc, which returns the doc
id of the named buffer whose name you pass in. So if you catch copy
events and reroute them to a named paste buffer, then catch the paste
event and change the id attr in the paste buffer document before the
paste occurs, you could avoid creating a separate document. Having
said that, sounds to me like James' suggestion might be the easiest route.