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

  • Home
  • SEARCH
  • 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 9121625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:54:18+00:00 2026-06-17T05:54:18+00:00

I have two xml files: one is the actual data and the second has

  • 0

I have two xml files: one is the actual data and the second has a list of keys I’d for the nodes I’d like to extract from the data and after much searching and testing I thought I’d ask for help since I’m not getting my desired results.

Data File:

<?xml version="1.0" encoding="UTF-8"?>
<Items>
  <Item>
    <ItemKey>12345</ItemKey>
    <Name>Apple></Name>
    <Attribute>Red</Attribute>
  </Item>
  <Item>
    <ItemKey>67890</ItemKey>
    <Name>Orange</Name>
    <Attribute>Orange</Attribute>
  </Item>
  <Item>
    <ItemKey>12346</ItemKey>
    <Name>Grape</Name>
    <Attribute>Purple</Attribute>
  </Item>
  <Item>
    <ItemKey>67891</ItemKey>
    <Name>Pear</Name>
    <Attribute>Yellow</Attribute>
  </Item>
</Items>

Filter File:

<?xml version="1.0" encoding="UTF-8"?>
<Items>
  <Item>
    <ItemKey>12345</ItemKey>
    </Item>
  <Item>
    <ItemKey>12346</ItemKey>
  </Item>
</Items>

I am trying to transform the data file and extract only the and subnodes that match the ItemKey in the filter file. I’ve tried using several of the examples I’ve seen and used the following xml with no success:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>

    <xsl:variable name="filter" select="document('Filter.xml')/Item/*"/>

    <xsl:template match="/">
        <xsl:for-each select="Items/Item">
            <xsl:choose>
                <xsl:when test="$filter/Item/ItemKey[contains(., ./ItemKey)]">
                    <xsl:call-template name="Filtered"/>
                </xsl:when>
            </xsl:choose>
        </xsl:for-each>
    </xsl:template>

    <xsl:template name="Filtered">
        <xsl:text>&#x9;"</xsl:text>
        <xsl:value-of select="ItemKey" />, <xsl:value-of select="Name"/>
        <xsl:text>",&#xA;</xsl:text>
    </xsl:template>
</xsl:stylesheet>

As you can see I wish to convert to text and will format appropriately once I know I am getting the nodes I’m after. Thanks for any help you can offer.

  • 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-17T05:54:19+00:00Added an answer on June 17, 2026 at 5:54 am

    As simple as this:

    <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:template match="/">
         <xsl:copy-of select=
         "/*/Item[ItemKey = document('file:///c:/temp/delete/filter.xml')/*/*/ItemKey]"/>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the provided source XML document:

    <Items>
      <Item>
        <ItemKey>12345</ItemKey>
        <Name>Apple></Name>
        <Attribute>Red</Attribute>
      </Item>
      <Item>
        <ItemKey>67890</ItemKey>
        <Name>Orange</Name>
        <Attribute>Orange</Attribute>
      </Item>
      <Item>
        <ItemKey>12346</ItemKey>
        <Name>Grape</Name>
        <Attribute>Purple</Attribute>
      </Item>
      <Item>
        <ItemKey>67891</ItemKey>
        <Name>Pear</Name>
        <Attribute>Yellow</Attribute>
      </Item>
    </Items>
    

    and the provided “filter xml” is in the file: c:\temp\delete\filter.xml:

    <Items>
      <Item>
        <ItemKey>12345</ItemKey>
        </Item>
      <Item>
        <ItemKey>12346</ItemKey>
      </Item>
    </Items>
    

    the wanted, correct result is produced:

    <Item>
       <ItemKey>12345</ItemKey>
       <Name>Apple&gt;</Name>
       <Attribute>Red</Attribute>
    </Item>
    <Item>
       <ItemKey>12346</ItemKey>
       <Name>Grape</Name>
       <Attribute>Purple</Attribute>
    </Item>
    

    Explanation:

    Proper use of the standard XSLT function document().

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

Sidebar

Related Questions

I have a J2EE application which has two web.xml files. One is called web.live.xml
I have two layouts(xml files) and I want to flip from one page to
I have two xml files, one of them is dev.xml which has this code
I am have two xml files.. I first get one and loop through it
I have created two folders layout and layout-land with two xml files, one for
this is my situation: I have two org.w3c.dom.Document created from two xml files. What
I have two xml files but one file will contain an extra field. Ideally
I have two XML files that I need to parse into one record. The
I have two XML files located in res/xml/. One file is a normal XML
I have two xml files and I need to create one xsd for both.

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.