RE: MERGING 2 XML DOCS WITH dom4j parser
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. <DOCUMENT> <DOC1> <CONFIGINFO /> </DOC1> <H>Main document</H> <P>Hello world</P> </DOCUMENT> 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. Thanks Lea -----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 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 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format