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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:49:54+00:00 2026-06-06T06:49:54+00:00

I would like to join two xml files as illustrated below. However the question

  • 0

I would like to join two xml files as illustrated below. However the question i have is how do you do this with having an ID to join with. I want to do the join in regards to POSITION and not id. How would you do this for the following files?

File 1:

<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
  <data>
    <title>Title1</title>
    <description>Description1</description>
  </data>

  <data>
    <title>Title2</title>
    <description>Description2</description>
  </data>
</catalog>

File 2:

<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
  <data>
    <author>Author1</author>
    <date>12/34/5678</date>
  </data>

  <data>
    <author>Author2</author>
    <date>87/65/4321</date>
  </data>
</catalog>

Output:

<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
  <data>
    <title>Title1</title>
    <description>Description1</description>
    <author>Author1</author>
    <date>12/34/5678</date>
  </data>

  <data>
    <title>Title2</title>
    <description>Description2</description>
    <author>Author2</author>
    <date>87/65/4321</date>
  </data>
</catalog>

I know how to do this if you have a common ID field using the XSLT below, however how do you join on POSITION?

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes" />
  <xsl:variable name="with" select="'File2.xml'" />

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

  <xsl:template match="scene">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
      <xsl:variable name="info" select="document($with)/catalog/data[id=current()/id]/." />
      <xsl:for-each select="$info/*">
        <xsl:if test="name()!='myid'">
          <xsl:copy-of select="." />
        </xsl:if>
      </xsl:for-each>
    </xsl:copy>
  </xsl:template>
</xsl:transform>
  • 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-06T06:49:56+00:00Added an answer on June 6, 2026 at 6:49 am
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes" />
        <xsl:variable name="with" select="'File2.xml'" />
    
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()" />
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="data">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()" />
                <!--Determine the index of the current data element in this document.
                       Note: using position() may not always yield the desired number 
                             because other siblings (text(), comment(), 
                             processing-instruction(), 
                             or other elements) would affect position().
                             Also, counting preceeding-siblings that are data 
                             elements, not just any element. -->
                <xsl:apply-templates 
                    select="document($with)
                    /catalog
                    /data[position() 
                           = count(current()/preceding-sibling::data)+1]
                    /*[name()!='myid']" />
                    <!--kept filter for `myid` elements from example stylesheet, 
                        remove if not needed --> 
            </xsl:copy>
        </xsl:template>
    </xsl:transform>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables user and log. I would like to join the user
I have two variables which are comma separated lists. I would like to join
I have two tables which I would like to join by ID field. I
I need to find a way to join two XML files when they have
I have two lists List<WorkOrder> and List<PlannedWork> I would like join the two lists
I have a materialized view of a complex join, which I would like to
I'm using RealURL on a site where I would like to join two tables
I would like join two tables into 1 table that has one common column
I have two MySQL tables (product and price history) that I would like to
I have a two tables that look like this (this is an example of

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.