You can tackle this using the DOM API, where you load the skeletal XML into a tree structure and then update it incrementally, or you can tackle it using XSLT, where you define a transformation from the skeletal XML to the completed XML, using the parameter values either as stylesheet parameters or as a secondary input document.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference