I have the following XML document:
<?xml version="1.0" encoding="UTF-8"?>
<cars>
<car body="Wagon">
<text>Red</text>
</car>
<car body="Sedan">
<text>Yellow</text>
</car>
<car body="Sedan">
<text></text>
</car>
<car body="Wagon">
<textlist>
<text>Red</text>
<text>Green</text>
<text>Black</text>
<text>Blue</text>
</textlist>
</car>
<car body="Sedan">
<textlist>
<text>Yellow</text>
<text>Orange</text>
</textlist>
</car>
<car body="Fastback">
<textlist>
<text>Yellow</text>
<text>Red</text>
<text>Green</text>
<text>Black</text>
<text>Blue</text>
</textlist>
</car>
<car body="Fastback">
<textlist>
<text>Pink</text>
<text>Red</text>
<text>Orange</text>
</textlist>
</car>
</cars>
Using XSLT 1.0 I need to transform the XML document to this format:
<?xml version="1.0" encoding="UTF-8"?>
<cars>
<car type="Wagon">Red</car>
<car type="Sedan">Yellow</car>
<car type="Wagon">Green</car>
<car type="Wagon">Black</car>
<car type="Wagon">Blue</car>
<car type="Sedan">Orange</car>
</cars>
Notice that:
- body="Fastback" is excluded
- Duplicates are excluded (Red Wagon appears twice)
- Textlist multiple items are put as individual elements in the output XML
- Ignore empty values