[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: MERGING 2 XML DOCS WITH dom4j parser

Subject: RE: MERGING 2 XML DOCS WITH dom4j parser
From: Lea Allison <Lea.Allison@xxxxxxxxxxxxxx>
Date: Thu, 21 Mar 2002 10:10:42 +0100
dom4j merge documents
The problem I find with this method, is that by using a parameter / variable
to import the second document I have to use a for-each loop with the
$importedDoc to be able to apply the templates to this data.

Secondly, if I view the outputed XML from the stylesheet, it only shows the
first document. The 2nd doc in the param does not show.

Actually it would be ideal to get two combined documents returned to the
users browser as XML. ie.


	<H>Main document</H>
	<P>Hello world</P>

Where DOC1 would be the 2nd documented added to the first.

There is also another problem. The imported document is not always the same.
I vary the document based on language, so I need to dynamically name the
imported document.



-----Original Message-----
From: Michael Kay [mailto:michael.h.kay@xxxxxxxxxxxx]
Sent: Thursday 21 March 2002 10:00
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  MERGING 2 XML DOCS WITH dom4j parser

> 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?

Yes, write an XSLT stylesheet to do it, supplying one file as the primary
input document, and the other as a stylesheet parameter.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx

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


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
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
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

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

Current Thread


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.
First Name
Last Name
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.