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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:43:10+00:00 2026-06-16T00:43:10+00:00

I have two source xml files and I need to construct a new xml

  • 0

I have two source xml files and I need to construct a new xml file which contains elements chosen for one or other of the files depending on whether their ‘name’ is contained in a plain text file.

xml file a:

<data name="name1">
  <value>abc1</value>
</data>
<data name="name2">
  <value>abc2</value>
</data>
<data name="name3">
  <value>abc3</value>
</data>

xml file b:

<data name="name1">
  <value>xyz1</value>
</data>
<data name="name2">
  <value>xyz2</value>
</data>
<data name="name3">
  <value>xyz3</value>
</data>

text file:

name1
name3

desired output:

<data name="name1">
  <value>abc1</value>
</data>
<data name="name2">
  <value>xyz2</value>        <---- note this element is from file 'b'
</data>
<data name="name3">
  <value>abc3</value>
</data>

So the elements with names ‘name1’ and ‘name3’ come from ‘xml file a’ because they are listed in the text file, but ‘name2’ comes from ‘xml file b’ because it isn’t.

The actual names aren’t ‘name1’ etc, but arbitrary string identifiers, but they are unique within the files.

Is it possible to do this with XSLT?

  • 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-16T00:43:11+00:00Added an answer on June 16, 2026 at 12:43 am

    This transformation:

    <xsl:stylesheet version="2.0"   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
        <xsl:variable name="vNames" select=
        "tokenize(unparsed-text('file:///c:/temp/delete/Names.txt'), '\s')"/>
    
        <xsl:variable name="vDoc1" select="document('file:///c:/temp/delete/FileA.xml')"/>
        <xsl:variable name="vDoc2" select="document('file:///c:/temp/delete/FileB.xml')"/>
    
     <xsl:template match="/">
         <t>
           <xsl:sequence select=
            "$vDoc1/*/*[@name = $vNames],
             $vDoc2/*/*[not(@name = $vNames)]
            "/>
         </t>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on any XML document (not used) and having these two files:

    c:/temp/delete/FileA.xml:

    <t>
        <data name="name1">
            <value>abc1</value>
        </data>
        <data name="name2">
            <value>abc2</value>
        </data>
        <data name="name3">
            <value>abc3</value>
        </data>
    </t>
    

    c:/temp/delete/FileB.xml:

    <t>
        <data name="name1">
            <value>xyz1</value>
        </data>
        <data name="name2">
            <value>xyz2</value>
        </data>
        <data name="name3">
            <value>xyz3</value>
        </data>
    </t>
    

    c:/temp/delete/Names.txt:

    name1
    name3
    

    produces the wanted, correct result:

    <t>
       <data name="name1">
                <value>abc1</value>
          </data>
       <data name="name3">
                <value>abc3</value>
          </data>
       <data name="name2">
                <value>xyz2</value>
          </data>
    </t>
    

    Explanation:

    Proper use of the standard XSLT functions: unparsed-text() (2.0 and up only) and document() and the standard XPath 2.0 function tokenize()

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

Sidebar

Related Questions

I have two source files which I need to combine on a row by
I have Source Connector Type as 'File Reader' which is reading HL7 files and
I have two schema files one is imported from the other. When executing the
I have two large source trees. One of them has some out of date
Suppose I have two lists that holds the list of source file names and
I have a need to have a config.xml file in my Eclipse project, and
I have two sources: an xml-file containing definitions of several hundred data structures, basically
I need to parse xml files from two sources. Both xml files contain the
I have two large XML files(c.100MB) containing a number of items. I want to
I have an XML file (a sitemap using Google's <image:image> extensions) that I need

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.