Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9013445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:16:06+00:00 2026-06-16T03:16:06+00:00

I am completely new to XSLT so please bear with me. I have two

  • 0

I am completely new to XSLT so please bear with me.

I have two xml files that I am attempting to concatenate together using XSLT. I would like to combine the files such that any values specified in the second file override the first. E.g.

firstFile.xml

<person>
  <person-name>Sandy</person-name>
  <person-age>21</person-age>
</person>

<person>
  <person-name>Bob</person-name>
  <person-age>15</person-age>
</person>

override.xml

<person>
  <person-name>Bob</person-name>
  <person-age>21</person-age>
</person>

Result:

<person>
  <person-name>Sandy</person-name>
  <person-age>21</person-age>
</person>
<person>
  <person-name>Bob</person-name>
  <person-age>21</person-age>
</person>

My template for concatenating the 2 files is as follows:

  <xsl:template match="/">
     <!-- MainFile -->
     <xsl:copy-of select="/*"/>

      <!-- Overrides-->
      <xsl:copy-of select="document($overrideFile)/*"/>
  </xsl:template>

I was attempting to setup a for-each loop such that before copying each person in firstFile.xml check if there is a corresponding node in override.xml, but was unsuccessful.

Any tips would be greatly appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:16:08+00:00Added an answer on June 16, 2026 at 3:16 am

    This transformation:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:param name="pDoc2Url" select="'file:///c:/temp/delete/override.xml'"/>
     <xsl:variable name="vDoc2" select="document($pDoc2Url)"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="/*">
      <t>
        <xsl:apply-templates
           select="person[not(person-name = $vDoc2/*/person/person-name)]"/>
        <xsl:apply-templates select="$vDoc2/*/person"/>
      </t>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the first of the provided XML documents (wrapped into a single top element — to be made a well-formed XML document):

    <t>
        <person>
            <person-name>Sandy</person-name>
            <person-age>21</person-age>
        </person>
        <person>
            <person-name>Bob</person-name>
            <person-age>15</person-age>
        </person>
    </t>
    

    and being passed as parameter the filename where the second document (again wrapped into a top element) resides — here is the corrected second document:

    c:/temp/delete/override.xml:

    <t>
        <person>
            <person-name>Bob</person-name>
            <person-age>21</person-age>
        </person>
    </t>
    

    produces the wanted, correct result:

    <t>
       <person>
          <person-name>Sandy</person-name>
          <person-age>21</person-age>
       </person>
       <person>
          <person-name>Bob</person-name>
          <person-age>21</person-age>
       </person>
    </t>
    

    II. A shorter, but less flexible solution — no identity rule and no xsl:apply-templates:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:param name="pDoc2Url" select="'file:///c:/temp/delete/override.xml'"/>
     <xsl:variable name="vDoc2" select="document($pDoc2Url)"/>
    
     <xsl:template match="/*">
      <t>
        <xsl:copy-of
           select="person[not(person-name = $vDoc2/*/person/person-name)]"/>
        <xsl:copy-of select="$vDoc2/*/person"/>
      </t>
     </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm completely new to databases, and have put something simple together using the helpful
Completely new to using simple XML library in PHP, and have been using the
Im completely new to XML/XSL/XSLT, and while i have been digging msdn, 3schools.com and
I'm completely new to using XSL, so if there's any information that I'm neglecting
I am completely new to chipmunk and I have just been using it for
Completely new to asp.net mvc... completely new to web apps so bear with me...
Completely new to java and I have been playing around with regex in a
I am completely new to HTML5 and have been reading about it for the
I am completely new to the world of PostgreSQL, please be patient with me.
I'm completely new with IFC files. For my company I need to read IFC

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.