To simplify things I have decided to first transform the input document into an intermediate form, and then to transform that into the final output.
During both phases I am using "generate-id" to form internal links within the document. In phase #1 the id's are generated from the input document. In phase #2 the id's are generated from the intermediate document.
Here is an example:
Is it possible that "generate-id" will return "GeneratedID1" again despite being from a different document tree, but of a similar structure?
Phase #1 is stored in a variable, and then Phase #2 is generated from that. So both parses are completed within the same transform.
I am using XSLT 2.0 with Saxon.