[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Merging common tags of 2 xml files


Subject: Re: [xsl] Merging common tags of 2 xml files
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 6 Aug 2014 12:24:27 -0000

varun bhatnagar varun292006@xxxxxxxxx wrote:

But I am sorry this is not the root element. There are few more elements
above this one and if I do this then the whole xml is getting written twice.
Is there anything else I can do?

Yes, assuming you know a pattern to identify the parent element of the elements to merge then change




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

         </xsl:copy>
       </xsl:template>

to e.g.


  <xsl:template match="/root/foo/config">
    <xsl:copy>
      <xsl:apply-templates select="@* , $doc2/root/foo/config, node()"/>
    </xsl:copy>
  </xsl:template>


or for instance, as long as "config" suffices to identify the parent element of the elements you want to merge it should suffice to use


  <xsl:template match="config">
    <xsl:copy>
      <xsl:apply-templates select="@* , $doc2//config, node()"/>
    </xsl:copy>
  </xsl:template>


Current Thread
Keywords