[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

Subject: Re: Using XSLT to Append a XML Document to a Master XML Document
From: Francis Norton <francis@xxxxxxxxxxx>
Date: Tue, 07 Aug 2001 22:07:04 +0100
xslt append
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


Current Thread
  • param problem
    • Earl Spencer - Tue, 7 Aug 2001 12:19:03 -0400 (EDT)
      • Michael Kay - Tue, 7 Aug 2001 13:01:20 -0400 (EDT)
        • dante - Tue, 7 Aug 2001 13:23:12 -0400 (EDT)
          • Michael Kay - Tue, 7 Aug 2001 14:16:52 -0400 (EDT)
          • Francis Norton - Tue, 7 Aug 2001 17:12:07 -0400 (EDT) <=
      • <Possible follow-ups>
      • Earl Spencer - Tue, 7 Aug 2001 13:22:58 -0400 (EDT)

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.