I am new to XML and XSL. I am trying to take a XML strings generated by our vendor software and translate it into Excel format. The XML can have repeating Rows that each have a
IIUC, you want to transpose the given table - rows to columns, fields to rows. The foilowing stylesheet shows how this can be done. For simplicity, this generates an HTML table - the adjustment for an Excel worksheet should be trivial.
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/RpcData">
<xsl:variable name="col" select="RepeatingFieldSet/Row"/>
<xsl:variable name="row" select="RepeatingFieldSet/Row[1]/Fld"/>
<table border="1">
<!-- header row -->
<tr>
<th>Field</th>
<xsl:for-each select="$col">
<th>
<xsl:value-of select="@Index"/>
</th>
</xsl:for-each>
</tr>
<!-- data rows -->
<xsl:for-each select="$row">
<xsl:variable name="i" select="position()"/>
<tr>
<th><xsl:value-of select="@Nm"/></th>
<xsl:for-each select="$col">
<td>
<xsl:value-of select="Fld[$i]"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
Applied to your example input, the (rendered) result will be: