XSLT for each does not display all entries from XML
If you want to have a row for each promotion
, then create only one tr
for each promotion
. And use a relative path from the current promotion
to get the values for the row's cells. Also create the html
and table
wrappers before calling xsl:for-each
to create the table rows.
Here is a simplified example:
XST 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" />
<xsl:template match="/rss">
<html>
<body>
<table border="1">
<xsl:for-each select="channel/promotions/promotion">
<tr>
<td>
<xsl:value-of select="title" />
</td>
<td>
<xsl:value-of select="description" />
</td>
<!-- more fields -->
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Applied to your input example, this will return:
Result
<html>
<body>
<table border="1">
<tr>
<td>Good deal!</td>
<td>this is a good deal</td>
</tr>
<tr>
<td>bad deal!</td>
<td>This is a bad deal</td>
</tr>
<tr>
<td>Super deal!</td>
<td>This deal is superb.</td>
</tr>
</table>
</body>
</html>
Rendered as:
Inside of the for-each
, instead of the absolute paths you have used, like <xsl:value-of select="/rss/channel/promotions/promotion/image" />
, use relative ones, like <xsl:value-of select="image"/>
.