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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:41:24+00:00 2026-05-14T20:41:24+00:00

I have two documents that I need to merge, that happen in a way

  • 0

I have two documents that I need to merge, that happen in a way that I don’t seem to be able to find covered in other examples. Namely, that it needs to match not only on a node’s attribute at one level, but also on the value of an attribute a node level below that, to get that node’s value.

I’m trying to take this sample:

<?xml version="1.0" encoding="UTF-8" ?>
<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <marc:record>
    <marc:datafield tag="035" ind1=" " ind2=" ">
        <marc:subfield code="a">12345</marc:subfield>
    </marc:datafield>
    <marc:datafield tag="041" ind1=" " ind2=" ">
        <marc:subfield code="a">eng</marc:subfield>
    </marc:datafield>
    <marc:datafield tag="650" ind1=" " ind2="4">
        <marc:subfield code="a">Art</marc:subfield>
    </marc:datafield>
    <marc:datafield tag="949" ind1=" " ind2=" ">
        <marc:subfield code="i">Review of conference proceedings</marc:subfield>
    </marc:datafield>
  </marc:record>
  <marc:record>
    <marc:datafield tag="035" ind1=" " ind2=" ">
        <marc:subfield code="a">54321</marc:subfield>
    </marc:datafield>
    <marc:datafield tag="041" ind1=" " ind2=" ">
        <marc:subfield code="a">eng</marc:subfield>
    </marc:datafield>
    <marc:datafield tag="650" ind1=" " ind2="4">
        <marc:subfield code="a">Byzantine</marc:subfield>
    </marc:datafield>
  </marc:record>
</marc:collection>

And when the value of “datafield” ‘035’, “subfield” ‘a’ matches e.g. “12345”

<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim"
xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <marc:record>
    <marc:datafield ind2=" " ind1=" " tag="035">
        <marc:subfield code="a">12345</marc:subfield>
    </marc:datafield>
    <marc:datafield ind2="4" ind1=" " tag="650">
        <marc:subfield code="a">General works</marc:subfield>
        <marc:subfield code="x">Historians and critics</marc:subfield>
        <marc:subfield code="x">Smith, John, 1834-1917</marc:subfield>
    </marc:datafield>
    <marc:datafield ind2="4" ind1=" " tag="650">
        <marc:subfield code="a">Généralités</marc:subfield>
        <marc:subfield code="x">Historiens et critiques d'art</marc:subfield>
        <marc:subfield code="x">Dietrichson, Lorentz, 1834-1917</marc:subfield>
    </marc:datafield>
    <marc:datafield ind2=" " ind1=" " tag="654">
        <marc:subfield code="a">General works</marc:subfield>
    </marc:datafield>
    <marc:datafield ind2=" " ind1=" " tag="654">
        <marc:subfield code="a">Généralités</marc:subfield>
        <marc:subfield code="b">Historiens et critiques d'art</marc:subfield>
        <marc:subfield code="b">Smith, John, 1834-1917</marc:subfield>
    </marc:datafield>
  </marc:record>      
  <marc:record>
    <marc:datafield ind2=" " ind1=" " tag="035">
        <marc:subfield code="a">54321</marc:subfield>
    </marc:datafield>
    <marc:datafield ind2="4" ind1=" " tag="650">
        <marc:subfield code="a">General works</marc:subfield>
        <marc:subfield code="x">Historians and critics</marc:subfield>
        <marc:subfield code="x">Lange, Julius Henrik, 1838-1896</marc:subfield>
    </marc:datafield>
  </marc:record>
</marc:collection>

The result should be:

<?xml version="1.0" encoding="UTF-8" ?>
<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <marc:record>
    <marc:datafield tag="035" ind1=" " ind2=" ">
        <marc:subfield code="a">12345</marc:subfield>
    </marc:datafield>
    <marc:datafield tag="041" ind1=" " ind2=" ">
        <marc:subfield code="a">eng</marc:subfield>
    </marc:datafield>
    <marc:datafield tag="650" ind1=" " ind2="4">
        <marc:subfield code="a">Art</marc:subfield>
    </marc:datafield>
    <marc:datafield ind2="4" ind1=" " tag="650">
        <marc:subfield code="a">General works</marc:subfield>
        <marc:subfield code="x">Historians and critics</marc:subfield>
        <marc:subfield code="x">Smith, John, 1834-1917</marc:subfield>
    </marc:datafield>
    <marc:datafield ind2="4" ind1=" " tag="650">
        <marc:subfield code="a">Généralités</marc:subfield>
        <marc:subfield code="x">Historiens et critiques d'art</marc:subfield>
        <marc:subfield code="x">Dietrichson, Lorentz, 1834-1917</marc:subfield>
    </marc:datafield>
    <marc:datafield ind2=" " ind1=" " tag="654">
        <marc:subfield code="a">General works</marc:subfield>
    </marc:datafield>
    <marc:datafield ind2=" " ind1=" " tag="654">
        <marc:subfield code="a">Généralités</marc:subfield>
        <marc:subfield code="b">Historiens et critiques d'art</marc:subfield>
        <marc:subfield code="b">Smith, John, 1834-1917</marc:subfield>
    </marc:datafield>
    <marc:datafield tag="949" ind1=" " ind2=" ">
        <marc:subfield code="i">Review of conference proceedings</marc:subfield>
    </marc:datafield>
  </marc:record>
  <marc:record>
    <marc:datafield tag="035" ind1=" " ind2=" ">
        <marc:subfield code="a">54321</marc:subfield>
    </marc:datafield>
    <marc:datafield tag="041" ind1=" " ind2=" ">
        <marc:subfield code="a">eng</marc:subfield>
    </marc:datafield>
    <marc:datafield tag="650" ind1=" " ind2="4">
        <marc:subfield code="a">Byzantine</marc:subfield>
    </marc:datafield>
    <marc:datafield ind2="4" ind1=" " tag="650">
        <marc:subfield code="a">General works</marc:subfield>
        <marc:subfield code="x">Historians and critics</marc:subfield>
        <marc:subfield code="x">Lange, Julius Henrik, 1838-1896</marc:subfield>
    </marc:datafield>
  </marc:record>
</marc:collection>

I’ve tried using examples that I’ve found that did lookups, but none of them seemed to work. I didn’t include any of my XSL, because all of my results were disasterous. I keep looking at it, like it must be simple, but I’m just not getting any decent results. Any help or pointers would be greatly appreciated.

Thanks!

  • 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-05-14T20:41:24+00:00Added an answer on May 14, 2026 at 8:41 pm

    I think I have an answer for you. It’s not the most elegant but it works. Basically, you run the stylesheet against one of the XML files you are trying to merge and then you use the document function to gain access to the other XML file. Iterate through each record in the first XML file and find the matching point. Then iterate through the second document and find the matching record and pull the appropriate nodes in.

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

    <xsl:variable name="doc2" select="document('FourBabyMarcs.xml')"/>
    
    <xsl:template match="/">
        <marc:collection>
            <xsl:for-each select="marc:collection/marc:record">
                <marc:record>
    
                    <xsl:for-each select="marc:leader">
                        <xsl:copy-of select="."/>
                    </xsl:for-each>
    
                    <xsl:for-each select="marc:controlfield">
                        <xsl:copy-of select="."/>
                    </xsl:for-each>
    
                    <xsl:for-each select="marc:datafield">
                        <xsl:copy-of select="."/>
                    </xsl:for-each>
    
                    <xsl:variable name="ID">
                        <xsl:value-of select="marc:datafield[@tag='035']/marc:subfield[@code='a']"/>
                    </xsl:variable>
    
                    <xsl:for-each select="$doc2/*/marc:record">
                            <xsl:if test="marc:datafield[@tag='035']/marc:subfield[@code='a']=$ID">
                                <xsl:for-each select="marc:datafield">
                                    <xsl:if test="@tag='650'">
                                        <xsl:copy-of select="."/>
                                    </xsl:if>
                                    <xsl:if test="@tag='654'">
                                        <xsl:copy-of select="."/>
                                    </xsl:if>
                                </xsl:for-each>
                            </xsl:if>
                    </xsl:for-each>
                </marc:record>
            </xsl:for-each>
        </marc:collection>
    </xsl:template>
    

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

Sidebar

Related Questions

I have two documents with a simple schema that I need to compare: current
I have two documents both are similar but I need to find an elegant
Suppose I have two documents that are identical except the lines are shuffled. Is
I have two XmlDocuments that both have a namespace attribute specified. Both documents have
I have a loop that calculates the similarity between two documents. It collects all
So I have two documents that both have allot of properties. One document is
Using xslt/xpath, I need to be able to select the two elements which have
I have a requirement to find items in a Lucene index that have two
I need to merge two XML documents, overwriting the overlapsed attributes and elements. For
I have two array I need to merge, and using the Union (|) operator

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.