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

Re: Inserting parts of a xml document

Subject: Re: Inserting parts of a xml document
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 11 Apr 2001 15:23:45 +0100
xslt copy and insert xml
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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