XML Declaration standalone="yes" lxml

Specify standalone using tree.docinfo.standalone.

Try following:

from lxml import etree
tree = etree.fromstring(templateXml).getroottree() # NOTE: .getroottree()

xmlFileOut = '/Users/User1/Desktop/Python/Done.xml'   

with open(xmlFileOut, "w") as f:
    f.write(etree.tostring(tree, pretty_print=True, xml_declaration=True,
                           encoding=tree.docinfo.encoding,
                           standalone=tree.docinfo.standalone))

You can pass standalone keyword argument to tostring():

etree.tostring(tree, pretty_print = True, xml_declaration = True, encoding='UTF-8', standalone=True)