How can I replace the XML element tag name with the attribute value using a stylesheet? The XML file structure is fairly simple and I want to replace the element tag name (DataColumn) using the attribute value from the element. I am working with SSIS. XML file is the data source. I understand that there might be more than one ways to parse the XML file but I am looking for XML transformation approach in the SSIS. The alternate solution I am able to come up is the PIVOT component. However, it becomes quite trivial if the XML file contains 30 or more elements. Here is the XML structure. I have abbreviated content so that it won't be too lengthy.
<?xml version="1.0" encoding="utf-8"?>
<RootNode>
<ResponseHeader />
<CustomReport Name="Sample Test" ID="000">
<DataRow>
<DataColumn Name="Order ID">12345654</DataColumn>
<DataColumn Name="Company ID">656584</DataColumn>
<DataColumn Name="First Name">John</DataColumn>
<DataColumn Name="Last Name">Smith</DataColumn>
<DataColumn Name="Email">[email protected]</DataColumn>
<DataColumn Name="Address 1">13542 S Main Street</DataColumn>
<DataColumn Name="Address 2"></DataColumn>
<DataColumn Name="City">Dallas</DataColumn>
<DataColumn Name="State">TX</DataColumn>
<DataColumn Name="Zip">75236</DataColumn>
<DataColumn Name="Country">United States</DataColumn>
<DataColumn Name="Phone">000-000-0000</DataColumn>
<DataColumn Name="Fax"></DataColumn>
</DataRow>
<DataRow>
<DataColumn Name="Order ID">5432354</DataColumn>
<DataColumn Name="Company ID">545454</DataColumn>
<DataColumn Name="First Name">Jane</DataColumn>
<DataColumn Name="Last Name">Smith</DataColumn>
<DataColumn Name="Email">[email protected]</DataColumn>
<DataColumn Name="Address 1">213213 W Main Blvd.</DataColumn>
<DataColumn Name="Address 2"></DataColumn>
<DataColumn Name="City">Baltimore</DataColumn>
<DataColumn Name="State">MD</DataColumn>
<DataColumn Name="Zip">21207</DataColumn>
<DataColumn Name="Country">United States</DataColumn>
<DataColumn Name="Phone">000-000-0000</DataColumn>
<DataColumn Name="Fax"></DataColumn>
</DataRow>
</CustomReport>
</RootNode>
Here is the desired output:
<?xml version="1.0" encoding="utf-8"?>
<RootNode>
<ResponseHeader />
<CustomReport Name="Sample Test" ID="000">
<DataRow>
<Order ID>12345654</Order ID>
<Company ID>656584</Company ID>
<First Name>John</First Name>
<Last Name>Smith</Last NAme>
<Email>[email protected]</Email>
<Address 1>13542 S Main Street</Address 1>
<Address 2></Address2>
<City>Dallas</City>
<State>TX</State>
<Zip>75236</Zip>
<Country>United States</Country>
<Phone>000-000-0000</Phone>
<Fax></Fax>
</DataRow>
<DataRow>
<Order ID>5432354</Order ID>
<Company ID>545454</Company ID>
<First Name>Jane</First Name>
<Last Name>Smith</Last Name>
<Email>[email protected]</Email>
<Address 1>213213 W Main Blvd.</Address 1>
<Address 2></Address 2>
<City>Baltimore</City>
<State>MD</State>
<Zip>21207</Zip>
<Country>United States</Country>
<Phone>000-000-0000</Phone>
<Fax></Fax>
</DataRow>
</CustomReport>
</RootNode>
If this subject has been posted and answered before, please point me to the right link. Thank you!