Re: [xsl] MERGING 2 XML DOCS WITH dom4j parser

Subject: Re: [xsl] MERGING 2 XML DOCS WITH dom4j parser
From: Mike Brown <mike@xxxxxxxx>
Date: Thu, 21 Mar 2002 01:45:49 -0700 (MST)
Lea Allison wrote:
> does anyone know how I can merge two XML files together (one on top of the
> other) using the dom4j parser so that my xsl transformation will read it as
> a single XML document?

Is it really necessary to do it at the XML parsing level? There is a
requirement that an XML document contain just a single element at the top
level, so it is impossible to create a well-formed document that is the
composite of two other well-formed documents, unless you wrap the whole thing
in a dummy element. I don't think this is really what you want.

If all you want to do is use 2 source documents in your transformation, use
XSLT's document function. For example, to get the union of root nodes from the
main source tree and another doc:

  <xsl:variable name="bothDocs" select="/|document('otherdoc.xml')"/>

Then you can refer to $bothDocs/path/to/some/nodes. The initial slash
is the root node of the main source tree; "|" means union of two node-sets, 
and the document() call returns the root node of otherdoc.xml.

You can, of course, use the document() function separately to access
just that document's node tree.

   - Mike
____________________________________________________________________________
  mike j. brown                   |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  personal: http://hyperreal.org/~mike/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread