I need to transform an XML string using XSLT in Javascript. While the XSLT is stored in its own file, the XML is part of a bigger XML document, and therefor stored as a string in a variable.
My current solution looks as follows:
xslt = document.implementation.createDocument("","",null);
xslt.async = false;
xslt.load('xslfile.xsl');
xml = document.implementation.createDocument("","",null);
// here I need to include the XML as it is in the document
xsltProc.importStylesheet(xslt);
xml_dom = xsltProc.transformToDocument(xml);
output += new XMLSerializer().serializeToString(xml_dom.documentElement);
When I save the content of the variable to a file and include it the way I included the XSLT file, I get the desired output (the transformed XML):
xml = document.implementation.createDocument("","",null);
xml.async = false;
xml.load('xmlinput.xml');
I need a way to include the content of the variable to the xml DOM document...or is there a more elegant way?
thanks in advance