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

Subject: RE: [xsl] transforming multiple xml sources into a single stream
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 17 Oct 2003 12:04:53 +0100
> 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:

Current Thread