[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Using XSLT to Append a XML Document to a Master XM
Hi Dante, dante wrote: > > Is it possible (using a xslt stylesheet) to append the content of one xml > doc to the end of a master xml doc? Yes, provided the data is held in a file or other URL-addressable resource - see http://www.w3.org/TR/xslt.html#function-document. You can may also be able to pass XML documents in as global parameters - see the attached jscript for a demo of this using msxml4. (Feature should work using msxml3 too.) This makes a more attractive prospect if you're working with large in-memory documents in a heavily stressed server environment and you don't want the load of serialising, saving, re-loading and re-parsing the documents in question - it also allows you to import the results of HTTP POST or SOAP based web services efficiently. Francis. --- C:\xml>type t.xml <?xml version="1.0" encoding="UTF-8"?> <a b="c"/> C:\xml>type t.xslt <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:param name="importXML" /> <xsl:template match="/"> <root> <xsl:for-each select="$importXML//@*"> <xsl:value-of select="concat('@', name(), ': ', .)" /> </xsl:for-each> </root> </xsl:template> </xsl:stylesheet> C:\xml>importXML t.xml t.xslt t.xml <?xml version="1.0"?> <root>@b: c</root> --- // This file is: importXML.js // first parameter is an XML files to be read in; // second parameter is the XSLT file // third parameter is the name of an XML file to be merged in. // validate parameters if(WScript.Arguments.length != 3) { WScript.Echo("importXML takes three arguments - XML, XSLT and importXML - eg:"); WScript.Echo('importXML books.xml books.xslt authors.xml'); } else { importXML(WScript.Arguments(0), WScript.Arguments(1), WScript.Arguments(2)); } function importXML(datafile, transform, importXML) { // load the datafile var xml = loadXML(datafile); // load the transform var xsl = new ActiveXObject("Msxml2.XSLTemplate.4.0"); var xslDoc = loadXML(transform); xsl.stylesheet = xslDoc; var xslProc = xsl.createProcessor(); // load the importXML var imp = loadXML(importXML); // add the import as a parameter xslProc.addParameter("importXML", imp); // do the transform xslProc.input = xml; xslProc.transform(); WScript.Echo(xslProc.output); } function loadXML(source, schemaCache) { var xmlDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0"); xmlDoc.async = false; if (schemaCache != undefined) { xmlDoc.schemas = schemaCache; } xmlDoc.load(source); if(xmlDoc.parseError.errorCode != 0) { loadError(source, xmlDoc); WScript.Quit(1); } return xmlDoc; } function loadError(source, xmlDoc) { WScript.Echo("Error loading " + source); WScript.Echo("Code: " + xmlDoc.parseError.errorCode); WScript.Echo("Source: " + xmlDoc.parseError.srcText); WScript.Echo("Line: " + xmlDoc.parseError.line); WScript.Echo("Error: " + xmlDoc.parseError.reason); } XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|