I have to transform one XML file into another set suitable for specific needs. Transforming XML is not new, but transforming it dynamically from elements to Attributes is somewhat intriguing.
Also there is a need to query the parent element using child element's text value.
This is what I want to achieve (data is anonymized):
Source File
<PARTS>
<PART>
<Name>Valve</Name>
<Code>1</Code>
<Color>Brown</Color>
</PART>
<PART>
<Name>Filter</Name>
<Code>2</Code>
<Color>Green</Color>
</PART>
<PART>
<Name>Plug</Name>
<Code>3</Code>
<Color>Brown</Color>
</PART>
</PARTS>
Transform to target XML file 1, filtering on color sub-element:
<PARTS>
<PART Name="Valve" Code=1 Color="Brown" />
<PART Name="Plug" Code=3 Color="Brown" />
</PARTS>
Transform to target XML file 2, filtering on color sub-element:
<PARTS>
<PART Name="Filter" Code=2 Color="Green" />
</PARTS>