Do not use a template; instead use xml2js to transform js to xml and vice-versa. Write a convert test.