I have the following XML file:-
<?xml version="1.0" encoding="UTF-8"?>
<viewentries>
<viewentry position="1">
<entrydata columnnumber="0">
<text>Text1</text>
</entrydata>
<entrydata columnnumber="1">
<text>Text2</text>
</entrydata>
<entrydata columnnumber="2">
<text>Text3</text>
</entrydata>
</viewentry>
<viewentry position="2">
<entrydata columnnumber="0">
<text>Text1</text>
</entrydata>
<entrydata columnnumber="1">
<text>Text2</text>
</entrydata>
<entrydata columnnumber="2">
<text>Text3</text>
</entrydata>
</viewentry>
</viewentries>
I need to transform this XML file using an XSL stylesheet to the following:-
<?xml version="1.0" encoding="UTF-8"?>
<records>
<record position="1" col0="Text1" col1="Text2" col2="Text3"/>
<record position="2" col0="Text1" col1="Text2" col2="Text3"/>
</records>
I have no real idea where to start.
Each element needs to be converted to a element, pulling through the position attribute, however each needs to be made into the attribute name, and each child attribute needs to be made into the attribute value.
Any help is greatly appreciated.
This transformation:
when applied on the provided XML document:
produces the wanted, correct result:
Explanation:
Proper use of templates, the
xsl:attributeinstruction and AVT.