This is something related to XSL transformations. input.xml
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="/x/transform.xsl"?>
<!-- input file root node-->
<message>
<header>
<!--Many descendents will be there -->
</header>
<body>
<!-- some other several elements will be there-->
<TaskList>
<TaskItem>
<DataPoint>
<Name>software.prog_name</Name>
<Target>JAVA</Target>
</DataPoint>
<DataPoint>
<Name>software.prog_rev</Name>
<Target>1</Target>
</DataPoint>
<DataPoint>
<Name>software.sw_product_id</Name>
<Target>1000</Target>
</DataPoint>
<DataPoint>
<Name>software.limits_file_name</Name>
<Target>limits.txt</Target>
</DataPoint>
<DataPoint>
<Name>software.limits_file_rev</Name>
<Target>2</Target>
</DataPoint>
<DataPoint>
<Name>hw_exp.class</Name>
<Target>Car</Target>
</DataPoint>
<DataPoint>
<Name>hw_exp.type</Name>
<Target>B</Target>
</DataPoint>
<DataPoint>
<Name>hw_exp.rev</Name>
<Target>32</Target>
</DataPoint>
<DataPoint>
<Name>prompt_id</Name>
<Target>100</Target>
</DataPoint>
</TaskItem>
<AutomationParam>
<Profile>Profile 1</Profile>
<SubGroup>1</SubGroup>
<Name>software.prog_name</Name>
<Value>JAVA</Value>
</AutomationParam>
<AutomationParam>
<Profile>Profile 1</Profile>
<SubGroup>1</SubGroup>
<Name>software.sw_product_id</Name>
<Value>1000</Value>
</AutomationParam>
<AutomationParam>
<Profile>Profile 1</Profile>
<SubGroup>2</SubGroup>
<Name>hw_exp.class</Name>
<Value>Animal</Value>
</AutomationParam>
<AutomationParam>
<Profile>Profile 1</Profile>
<SubGroup>2</SubGroup>
<Name>hw_exp.type</Name>
<Value>B</Value>
</AutomationParam>
<AutomationParam>
<Profile>Profile 1</Profile>
<SubGroup>3</SubGroup>
<Name>hw_exp.class</Name>
<Value>Flight</Value>
</AutomationParam>
<AutomationParam>
<Profile>Profile 1</Profile>
<SubGroup>3</SubGroup>
<Name>hw_exp.type</Name>
<Value>E</Value>
</AutomationParam>
<AutomationParam>
<Profile>Profile 1</Profile>
<SubGroup>3</SubGroup>
<Name>hw_exp.rev</Name>
<Value>1</Value>
</AutomationParam>
<AutomationParam>
<Profile>Profile 2</Profile>
<SubGroup>1</SubGroup>
<Name>software.sw_product_id</Name>
<Value>1000</Value>
</AutomationParam>
</TaskList>
</body>
</message>
After applying XSL tranform on input.xml the generated file be output.xml output.xml (It should be like this)
<?xml version="1.0" encoding="utf-8"?>
<!-- output file root node-->
<text>
<header>
<!--All descendents will/should be copied as it is-->
</header>
<body>
<sub_body>
<!-- All such several elements from input.xml will/should be there-->
<test_profile>
<software>
<prog_name>JAVA</prog_name>
<prog_rev>1</prog_rev>
<sw_product_id>1000</sw_product_id>
<limits_file_name>limits.txt</limits_file_name>
<limits_file_rev>2</limits_file_rev>
</software>
<hw_exp>
<class>Car</class>
<type>B</type>
<rev>32</rev>
</hw_exp>
<prompt_id>100</prompt_id>
</test_profile>
<test_profile>
<software>
<prog_name>JAVA</prog_name>
<sw_product_id>1000</sw_product_id>
</software>
<hw_exp>
<class>Animal</class>
<type>B</type>
</hw_exp>
<hw_exp>
<class>Flight</class>
<type>E</type>
<rev>1</rev>
</hw_exp>
</test_profile>
<test_profile>
<software>
<sw_product_id>1000</sw_product_id>
</software>
</test_profile>
</sub_body>
</body>
Please someone help me in achieving this, that would be a great help. I need XSL 1.0 (but not 2.x +) code.
Mapping Rules: a) one <test_profile> record in output.xml should be mapped to entire TaskList.TaskItem in input.xml b) you are seeing extra two <test_profile> elements [records] in output.xml as you are seeing <profile> element's values in input.xml as Profile 1 and Profile 2 [which means all Profile 1 related things should go into one different <test_profile> and all Profile 2 related things should go into another different <test_profile>. c) <header> element and its whole content (can be several descendents) should be copied as it is. d) <DataPoint> and <AutomationParams> are not fixed number of elements. These things can be 0 [either nothing] to infinity [many] which means all should be done dynamically and moreover there can be 0 to many profiles [i.e Profile 1, Profile 2, Profile 3, .. and it can be any string like jack, jill etc..,] for AutomationParams
Note: Think that this input.xml file is being populated dynamically based on the records in the database.