[xsl] Inserting parts of a xml document

Subject: [xsl] Inserting parts of a xml document
From: Martin Renner <m.renner@xxxxxxxxxx>
Date: Wed, 11 Apr 2001 15:53:00 +0159
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



Current Thread