Friday, 30 January 2015

XSLT - Multiple Rows




<Records>
<Record>
<Field>Grandpa Field</Field>
<Record>
<Field>Son Field</Field>
<Record>
<Field>Child Field 1</Field>
</Record>
<Record>
<Field>Child Field 2</Field>
</Record>
</Record>
</Record>
</Records>


Based on this XML structure and following a tutorial, I'm new to XSLT, I have created the following XLST transform file:



<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://ift.tt/tCZ8VR">

<xsl:template match="Records">
<html>
<body>
<table border="1">
<tr bgcolor="#9acd32">
<th>Grandpa Field</th>
<th>Son Field</th>
<th>Child Field</th>
</tr>
<tr><td>
<xsl:for-each select="Record">
<xsl:value-of select="Field"/>
</xsl:for-each></td>

<td><xsl:for-each select="Record/Record">
<xsl:value-of select="Field"/>
</xsl:for-each></td>
<td>
<xsl:for-each select="Record/Record/Record">
<xsl:value-of select="Field"/>
</xsl:for-each>
</td></tr>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>


Which gives me the following output:



Grandpa Field |Son Field | Child Field 1Child Field 2


What I need to get as my final output is:



Grandpa Field |Son Field | Child Field 1
Grandpa Field |Son Field | Child Field 2


Any ideas would be greatly appreciated! Mind you, the HTML portion is not necessary but it was helpful to me when seeing the results.


No comments:

Post a Comment