Altova Mailing List Archives

RE: [xsl] transforming multiple xml sources into a single stream

From: "Michael Kay" <mhk@--------->
Date: 10/17/2003 3:04:00 AM
> Hi,
> I am using Java1.4.1's API for Transformation. I have 2 
> different xml streams (not files on disk) in memory and have 
> to use transformation to merge them into a single xml stream. 
> Is this possible?
> I know there is way to merge 2 xml files into a single if the 
> files are on the disk, but I am wondering if we can do this 
> when streams are in memory. Hope there is a way!

There are two possible approaches. Both rely on the fact that you can
create a StreamSource or SAXSource object that wraps a stream of bytes
or characters in memory.

One is to supply the second document source as the value of a stylesheet
parameter. JAXP doesn't say what kinds of objects are acceptable as
parameters, so this approach may depend on which XSLT processor you are
using; but recent versions of Saxon, for example, will allow any kind of
Source object to be supplied as the parameter value in the
addParameter() method.

The other approach, which should work with any processor that implements
the JAXP API, is to write a URIResolver. You can then load the second
document from your stylesheet using a URI such as "memory://doc2.xml",
and your URIResolver can intercept this and return the Source object
that wraps the in-memory document.

Either way, take care to use setSystemId() on the Source object to
allocate some kind of base URI to the document.

Michael Kay

 XSL-List info and archive:


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.