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 8739685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:59:03+00:00 2026-06-13T10:59:03+00:00

Is it possible to join two xml files based on a node value like

  • 0

Is it possible to join two xml files based on a node value like SQL?

I have two xml files:

<MailPackage>
   <Mail>
      <id>1</id>
      <field_1>foo</field_1>
      ...
      <field_n>bar</field_n>
   </Mail>
   <Mail>
      <id>2</id>
      <field_1>... </field_1>
       ...
   </Mail>
   ....
</MailPackackage>

and

<Transaction_data>
   <Transaction>
     <id>1</id>
     <account_number>10 </account_number>
     ....
   </Transaction>
   <Transaction>
     <id>1</id>
     <account_number> 50 </account_number>
      ....
   </Transaction>
   <Transaction>
     <id>2</id>
     <account_number> 20 </account_number>
      ....
   </Transaction>
</Transaction_data>

Now I’d like to join the two xml files by the value of the ‘id’ node. The expected result is:

<MailPackage>
   <Mail>
      <id>1 </id>
      <field_1>foo </field_1>
      ...
      <field_n>bar </field_n>
      <Transaction_data>
         <Transaction>
            <Account_number>10</Account_number>
             ...
         </Transaction>
         <Transaction>
            <Account_number>50 </Account_number>
             ...
         </Transaction>
      </Transaction_data>
   </Mail>
   <Mail>
      <id> 2 </id>
      <Field_1> ...</Field_1>
       ...
      <Transactions>
         <Transaction>
            <Account_number> 20 </Account_number>
             ....
         </Transaction>
      </Transactions>

   </Mail>
</MailPackage>

Can you guys give some help, how to begin?

  • 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-13T10:59:04+00:00Added an answer on June 13, 2026 at 10:59 am

    You can define an <xsl:key> to group the Transaction elements by ID, then insert them at the appropriate places in the main file. This article explains a trick using <xsl:for-each> to select nodes matching a key from a secondary document – if you have XSLT 2.0 you don’t need this trick, just use the three-argument form of the key() function.

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:strip-space elements="*"/>
      <xsl:output method="xml" indent="yes" />
    
      <xsl:key name="trans" match="Transaction" use="id" />
    
      <!-- Identity template to copy everything we don't specifically override -->
      <xsl:template match="@*|node()">
        <xsl:copy><xsl:apply-templates select="@*|node()" /></xsl:copy>
      </xsl:template>
    
      <!-- override for Mail elements -->
      <xsl:template match="Mail">
        <xsl:copy>
          <!-- copy all children as normal -->
          <xsl:apply-templates select="@*|node()" />
          <xsl:variable name="myId" select="id" />
          <Transaction_data>
            <xsl:for-each select="document('transactions.xml')">
              <!-- process all transactions with the right ID -->
              <xsl:apply-templates select="key('trans', $myId)" />
            </xsl:for-each>
          </Transaction_data>
        </xsl:copy>
      </xsl:template>
    
      <!-- omit the id element when copying a Transaction -->
      <xsl:template match="Transaction/id" />
    </xsl:stylesheet>
    

    You would process the <MailPackage> document as the main input document, and the stylesheet references the transactions document internally.

    This all assumes that your Mail elements all have unique IDs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is is possible to programatically join two tables using Django's ORM? I have two
Possible Duplicate: How do I join two lines in vi? I have the following
Possible Duplicate: Join lines based on pattern I have the following file: test one
Is it possible to join two tables based on the same date, not factoring
I would like to check, is it possible to left join two tables using
Is it possible to join two ResultSets like join two tables in Java-oracle programming?
I have 3 tables, a,b,c It is possible to add left join for two
Is it possible to join two classes without specified mapping between them (using Criteria
Is it possible to do cross database joins in drupal? Say you have two
Is it possible to join the results of 2 sql SELECT statements in one

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.