Thanks for your response.
I am not in a position to update the Twig installation.
The code work "kind-of-ok" when I remove "TwigPrintOutsideRoots => 1". The program still changes PUBLIC to SYSTEM in doctype, and adds standalone="no" to the xml declaration. However I think I can work around these by acessing and modifying these in the object tree.
Thanks again.