0

I have a requirement as below.

I have an xml as below and xslt contains the xpaths to transform the xml. Is there any ready made xslt does the job.

<employeelist>
 <employee1>
 <name>xxx</name>
 <id>222</id>
 <salary>1111111</salary>
</employee1>

 <employee2>
 <name>xxx1</name>
 <id>22222</id>
 <salary>1222111111</salary>
</employee2>

</employeelist>

<xpathlist>

<xpath1 elename="name">/employeelist/employee1/name</xpath>
<xpath1 elename="id">/employeelist/employee1/id</xpath>
<xpath1 elename="salary">/employeelist/employee1/salary</xpath>

<xpath1 elename="name">/employeelist/employee2/name</xpath>
<xpath1 elename="id">/employeelist/employee2/id</xpath>
<xpath1 elename="salary">/employeelist/employee2/salary</xpath>

</xpathlist>

Let's I want to produce the below xml using above xslt and xml

<employeelist>
 <employee1>
 <name>xxx</name>
 <id>222</id>
 <salary>1111111</salary>
</employee1>

</employeelist>
storia321
  • 381
  • 2
  • 22

1 Answers1

0

I would compile the XML that contains the XPaths into meta-XSLT, and execute the meta-XSLT against the original input XML file.

Update: You can see a complete, working example of this technique in my answer to Annotating an xml instance from a list of xpath statements with xslt. If you can use XSLT 2.0 or 3.0, check out the techniques offered in the other answers as well.

Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240