2

file1.xml:

<config>
  <version>
     <input00 version ="1"/>
  </version>
</config>

file2.xml:

 <config>
  <version>
     <input01 version ="2"/>
  </version>
</config>

output.xml:

<config>
  <version>
     <input00 version ="1"/>
     <input01 version ="2"/>
  </version>
</config>

This is what I tried for generating a stylesheet: merge.xslt

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
</xsl:template>


<xsl:template match="/config">
     <xsl:copy>
        <xsl:apply-templates select="config"/>
        <xsl:apply-templates select="document('./file1.xml')/config/version" />
     </xsl:copy>
</xsl:template>


</xsl:stylesheet>

& this is how I run the xslt processor:

 $xsltproc merge.xslt file2.xml

this is all I get:

<?xml version="1.0"?>
<config/>

Please help.

Kirill Polishchuk
  • 54,804
  • 11
  • 122
  • 125
user2041627
  • 37
  • 1
  • 4

1 Answers1

3

Try this XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes"/>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
  </xsl:template>

  <xsl:template match="version">
    <xsl:copy>
      <xsl:apply-templates select="*"/>
      <xsl:apply-templates select="document('file1.xml')/config/version/*" />
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
Kirill Polishchuk
  • 54,804
  • 11
  • 122
  • 125