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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:39:49+00:00 2026-06-13T07:39:49+00:00

I need to pull data out of XML in some specific way using XPATH

  • 0

I need to pull data out of XML in some specific way using XPATH and XSLT

<data>      
    <person id="p1">         
        <name>User1</name>      
    </person>   
    <person id="p2">         
        <name>User2</name>      
    </person>  
    <person id="p3">         
        <name>User3</name>      
    </person>       
    <employee eid="emp1" pid="p1">         
        <dept>dept1</dept>      
    </employee> 
    <employee eid="emp2" pid="p3">         
        <dept>dept3</dept>      
    </employee>
    <employee eid="emp3" pid="p2">         
        <dept>dept1</dept>      
    </employee>
</data>

From the above example I need to create XMLs of each with the Person and the corresponding Employee elements in the output xml. The link between these two xmls is

person.id = employee.pid

like
XML1:

<person id="p1">         
<name>User1</name>      
</person>  
<employee eid="emp1" pid="p1">         
<dept>dept1</dept>      
</employee>

XML2:

<person id="p2">         
<name>User2</name>      
</person> 
<employee eid="emp3" pid="p2">         
 <dept>dept1</dept>      
</employee>

XML3:

<person id="p3">         
<name>User3</name>      
</person> 
<employee eid="emp2" pid="p3">         
<dept>dept3</dept>      
</employee>  

I have tried many ways but not able to get this.

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-06-13T07:39:50+00:00Added an answer on June 13, 2026 at 7:39 am

    XPath is a query language for XML documents — as such the evaluation of an XPath expression cannot modify an existing document or create a new XML document.

    What you want can best be achieved using XSLT 2.0 (XSLT 1.0 if only one result document is needed):

    <xsl:stylesheet version="2.0"   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
        <xsl:strip-space elements="*"/>
    
        <xsl:key name="kEmpByPid" match="employee" use="@pid"/>
    
     <xsl:template match="person">
      <xsl:result-document href="file:///c:/temp/delete/XML{position()}">
          <t>
                 <xsl:copy-of select=".|key('kEmpByPid', @id)"/>
             </t>
         </xsl:result-document>
     </xsl:template>
     <xsl:template match="text()"/>
    </xsl:stylesheet>
    

    When this XSLT 2.0 transformation is applied on the provided XML document:

    <data>
        <person id="p1">
            <name>User1</name>
        </person>
        <person id="p2">
            <name>User2</name>
        </person>
        <person id="p3">
            <name>User3</name>
        </person>
        <employee eid="emp1" pid="p1">
            <dept>dept1</dept>
        </employee>
        <employee eid="emp2" pid="p3">
            <dept>dept3</dept>
        </employee>
        <employee eid="emp3" pid="p2">
            <dept>dept1</dept>
        </employee>
    </data>
    

    the following three XML documents are created in “c:\temp\delete”:

    XML1:

    <t>
       <person id="p1">
          <name>User1</name>
       </person>
       <employee eid="emp1" pid="p1">
          <dept>dept1</dept>
       </employee>
    </t>
    

    XML2:

    <t>
       <person id="p2">
          <name>User2</name>
       </person>
       <employee eid="emp3" pid="p2">
          <dept>dept1</dept>
       </employee>
    </t>
    

    XML3:

    <t>
       <person id="p3">
          <name>User3</name>
       </person>
       <employee eid="emp2" pid="p3">
          <dept>dept3</dept>
       </employee>
    </t>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been given some poorly formatted data and need to pull numbers out
i need to pull data out of an xml file based on certain field
i have some data files, and i need to pull some info out. i'd
I need to pull out all of the NodeGroup elements out of an XML
I am using SoapClient to pull data out of a sharepoint list. If its
I am trying to pull out data from an XML document that seems to
I need to pull some data from the API. It returns the GET in
Need to pull out the Employees who have a pager. <Employees> <Employee> <Name>Michael</Name> <Phone
I have two strings that I need to pull data out of but can't
I need to pull out data from a plist array and put it in

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.