related to the last note.
invoking transform() on th1.getTransformer() with the result pointing again on th1 is not correct. It will be processed twice.
using new Transformer() like shown in the initial post is the correct way.
t.transform(new StreamSource(new File("in.xml")), new SAXResult(th1));