I've run into a snag with the following XSLT transformation,the goal is to output each item, quantity of the XML in a cell next to each foodgroup, if the goal is vague please inform:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="4.0" encoding="iso-8859-1" indent="yes"/>
<xsl:template match="/">
<html>
<body>
<h2>My Groceries</h2>
<table border="1">
<thead>
<tr bgcolor="#9acd32"><th scope="col" align="left">Food Group</th><th scope="col" align="left">Item</th><th scope="col" align="left">Quantity</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="groceryList/foodGroup">
<tr><td><xsl:value-of select="groupName"/></td><td><xsl:value-of select="item/name"/></td><td><xsl:value-of select="item/howMuch"/></td></tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Ouput So Far:
Code:
<html>
<body>
<h2>My Groceries</h2>
<table border="1">
<thead>
<tr bgcolor="#9acd32">
<th align="left" scope="col">Food Group</th><th align="left" scope="col">Item</th><th align="left" scope="col">Quantity</th>
</tr>
</thead>
<tbody>
<tr>
<td>Fruits and Vegetables</td><td>Pomegranate</td><td>2</td>
</tr>
<tr>
<td>Grains</td><td>Couscous</td><td>6 ounces</td>
</tr>
<tr>
<td>Candy</td><td>Crunchie Bar</td><td>1 gross</td>
</tr>
</tbody>
</table>
</body>
</html>
This the XML file:
Code:
<?xml version="1.0"?>
<groceryList>
<listName>My Shopping List</listName>
<foodGroup>
<groupName>Fruits and Vegetables</groupName>
<item>
<name>Pomegranate</name>
<howMuch>2</howMuch>
</item>
<item>
<name>Carrots</name>
<howMuch>1 pound</howMuch>
</item>
</foodGroup>
<foodGroup>
<groupName>Grains</groupName>
<item>
<name>Couscous</name>
<howMuch>6 ounces</howMuch>
</item>
</foodGroup>
<foodGroup>
<groupName>Candy</groupName>
<item>
<name>Crunchie Bar</name>
<howMuch>1 gross</howMuch>
</item>
</foodGroup>
</groceryList>
:D