[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Inserting parts of a xml document
Hi Martin, > I simply want to insert test2.xml/root/a/* into test1.xml/root/a. So I wrote the > following xslt: > > <xsl:template match="root/a"> > <xsl:apply-templates /> > <xsl:copy> > <xsl:apply-templates select="document('test2.xml')/root/a/node()" /> > </xsl:copy> > </xsl:template> > > But with this xslt the "<a>" and "</a>" are just around the second "<b>": In the above template, you're creating the 'a' element with the xsl:copy. The xsl:apply-templates before the copy is applying templates to (and therefore copying, since you're using the identity template) the children of a in test1.xml. The xsl:apply-template within the copy is applying templates to (and therefore copying) the children of a in test2.xml. All you need to do is to make the result of applying the templates to the children of a in test1.xml be added *within* the copy of the 'a' element, rather than before it: <xsl:template match="a"> <xsl:copy> <xsl:apply-templates /> <xsl:apply-templates select="document('test2.xml')/root/a/node()" /> </xsl:copy> </xsl:template> BTW, if this is all you're doing, you may as well use xsl:copy-of rather than xsl:apply-templates, to save the processor working through the nodes one by one: <xsl:template match="a"> <xsl:copy> <xsl:copy-of select="node()" /> <xsl:copy-of select="document('test2.xml')/root/a/node()" /> </xsl:copy> </xsl:template> I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ 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
|