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…
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):
When this XSLT 2.0 transformation is applied on the provided XML document:
the following three XML documents are created in “c:\temp\delete”:
XML1:
XML2:
XML3: