So you have an XSLT which transforms an XML document to HTML.
And now you want to change it so it also modifies the original document?
Okay. You can't do that with XSLT 1.0, as it can only output to one target. (Although there are proprietary extensions from various XSLT 1.0 implementations which allow you to output to more than one target.) If you want to use XSLT 2.0 -- which isn't bundled into the standard
Java API -- then you can write an XSLT 2.0 transform which outputs to as many targets as you like. Note however that outputting to the same document you're inputting from can't be done. (That's just a basic principle of computers, not specific to XSLT.) You could of course output the modified original document to a new document, and wrap the whole thing in a script or program which deleted the original and renamed the new.