This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Inserting parts of a xml document


Hi.

I have the following two xml files:

test1.xml
<root>
   <a>
     <b>
       <name>node1</name>
       <option>true</option>
     </b>
   </a>
</root>

test2.xml
<root>
   <a>
     <b>
       <name>node2</name>
       <option>false</option>
     </b>
   </a>
</root>

The result should be:
<root>
   <a>
     <b>
       <name>node1</name>
       <option>true</option>
     </b>
     <b>
       <name>node2</name>
       <option>false</option>
     </b>
   </a>
</root>

I simply want to insert test2.xml/root/a/* into test1.xml/root/a. So I wrote the 
following xslt:

     <xsl:template match="/">
        <xsl:apply-templates />
     </xsl:template>

     <xsl:template match="root/a">
         <xsl:apply-templates />
         <xsl:copy>
            <xsl:apply-templates select="document('test2.xml')/root/a/node()" />
         </xsl:copy>
     </xsl:template>

     <!-- copy all significant parts -->
     <xsl:template match="node()|attribute::*">
         <xsl:copy>
             <xsl:apply-templates select="node()|attribute::*" />
         </xsl:copy>
     </xsl:template>

But with this xslt the "<a>" and "</a>" are just around the second "<b>":
<root>
     <b>
       [data of "node1"]
     </b>
   <a>
     <b>
       [data of "node2"]
     </b>
   </a>
</root>

What do I have to change in my xslt file to get the correct result??


Martin


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]