I’ve asked a similar question here which was resolved.
However I have found that I am also facing an issue where the data appears as below, instead of having the header values contained in an XML tag.
<results>
<body>
<line>
<a>Column 1 Customer Name</a>
<a>Column 2 Customer Add</a>
<a>Column3</a>
<a>Column4</a>
</line>
<line>
<a>Data1</a>
<a>Data2</a>
<a>Data3</a>
<a>Data4</a>
</line>
<line>
<a>Data1</a>
<a>Data2</a>
<a>Data3</a>
<a>Data4</a>
</line>
</body>
</results>
I’ve managed to find a method (external to XSLT) to distinguish between the two types, but need to achieve the same results, as below.
<?xml version="1.0"?>
<results>
<header>
<a>Column 1 Customer Name</a>
<a>Column 2 Customer Add</a>
<a>Column3</a>
<a>Column4</a>
</header>
<body>
<line>
<Column1CustomerName>Data1</Column1CustomerName>
<Column2CustomerAdd>Data2</Column2CustomerAdd>
<Column3>Data3</Column3>
<Column4>Data4</Column4>
</line>
<line>
<Column1CustomerName>Data1</Column1CustomerName>
<Column2CustomerAdd>Data2</Column2CustomerAdd>
<Column3>Data3</Column3>
<Column4>Data4</Column4>
</line>
</body>
</results>
The amount of lines can be unlimited, however the “headers” will always be the first line.
I have the theory on how I need to do this, by
<xsl:template match="/results/body/line[0]">
However that’s about as far as I’ve got.
I was thinking it may be easier to complete a move of this data, to a tag “header” so I can execute the transformer as per the other question I asked, but do not know if this is a) the best approach, or b) possible?
As an additional question, would it be possible to put these two methods into a single XSLT?
Thanks in advance
When this transformation is applied on the provided XML document:
the wanted, correct result is produced: