Help with for-each loop
Hi guys
What i would like to do is to have a heading for each category and then list all products below in the for each
<Common>
<FruitProducts>
<Fruit>
<ParentCategoryID>2</ParentCategoryID>
<ProductID>46</ProductID>
<ProductLongName>Apricots</ProductLongName>
<StandardPrice></StandardPrice>
</Fruit>
<Fruit>
<ParentCategoryID>2</ParentCategoryID>
<ProductID>31</ProductID>
<ProductLongName>Avocadoes - large</ProductLongName>
<StandardPrice>3.5</StandardPrice>
</Fruit>
<Fruit>
<ParentCategoryID>2</ParentCategoryID>
<ProductID>32</ProductID>
<ProductLongName>Avocadoes - tray</ProductLongName>
<StandardPrice></StandardPrice>
</Fruit>
<Fruit>
<ParentCategoryID>3</ParentCategoryID>
<ProductID>66</ProductID>
<ProductLongName>Asparagus - bunch</ProductLongName>
<StandardPrice></StandardPrice>
</Fruit>
<Fruit>
<ParentCategoryID>3</ParentCategoryID>
<ProductID>2</ProductID>
<ProductLongName>Baby Carrots</ProductLongName>
<StandardPrice>2.99</StandardPrice>
</Fruit>
<Fruit>
<ParentCategoryID>3</ParentCategoryID>
<ProductID>67</ProductID>
<ProductLongName>Beans - flat 250g tray</ProductLongName>
<StandardPrice></StandardPrice>
</Fruit>
</FruitProducts>
</Common>
this is my XML what i would like to do is any thing with a parent category id of 2 to say FRUIT then all products under it then anything with parent category 3 to have a heading of vegitables then have all products underneath it and so forth for all categories.
I am listing all products on one page then the person will choose what they want then get directed to purchase them.
Is there a way of doing this in XSLT?
i am sure there is but i have no idea on how to do this.
Here is my code so far.
<xsl:for-each select="//Common/FruitProducts/Fruit">
<xsl:if test="ParentCategoryID = 2">
<tr>
<td width="418"><a href="#"><xsl:attribute name="onclick">NewWindow('/search/ViewProductPopUp.asp?ProductID=<xsl:value-of select="ProductID" />','name','600','400','yes');</xsl:attribute><xsl:value-of select="ProductLongName" /></a> $<xsl:value-of select="StandardPrice" /></td>
<td width="100"><span style="font-size:11px">Quantity to order:</span></td>
<td>
<input type="hidden" size="8">
<xsl:attribute name="name">Item_<xsl:value-of select="position()" /></xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="StandardPrice" /></xsl:attribute>
</input>
<input type="hidden" size="8">
<xsl:attribute name="name">price_<xsl:value-of select="position()" /></xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="StandardPrice" /></xsl:attribute>
</input>
<input value="0" size="5" maxlength="4">
<xsl:attribute name="name">qty_<xsl:value-of select="position()" /></xsl:attribute>
<xsl:attribute name="onblur">updatetotal()</xsl:attribute>
</input>
<input type="hidden"><xsl:attribute name="value"><xsl:value-of select="ShortName" /></xsl:attribute><xsl:attribute name="name">Qty_<xsl:value-of select="position()" /></xsl:attribute></input>
<input type="hidden"><xsl:attribute name="value">$<xsl:value-of select="StandardPrice" />,</xsl:attribute><xsl:attribute name="name">Qty_<xsl:value-of select="position()" /></xsl:attribute></input>
</td>
</tr>
</xsl:if>
<xsl:if test="ParentCategoryID = 3">
<tr>
<td width="418"><a><xsl:attribute name="href"><xsl:value-of select="ProductID" /></xsl:attribute><xsl:value-of select="ProductLongName" /></a> $<xsl:value-of select="StandardPrice" /></td>
<td width="100"><span style="font-size:11px">Quantity to order:</span></td>
<td>
<input type="hidden" size="8">
<xsl:attribute name="name">Item_<xsl:value-of select="position()" /></xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="StandardPrice" /></xsl:attribute>
</input>
<input type="hidden" size="8">
<xsl:attribute name="name">price_<xsl:value-of select="position()" /></xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="StandardPrice" /></xsl:attribute>
</input>
<input value="0" size="5" maxlength="4">
<xsl:attribute name="name">qty_<xsl:value-of select="position()" /></xsl:attribute>
<xsl:attribute name="onblur">updatetotal()</xsl:attribute>
</input>
<input type="hidden"><xsl:attribute name="value"><xsl:value-of select="ShortName" /></xsl:attribute><xsl:attribute name="name">Qty_<xsl:value-of select="position()" /></xsl:attribute></input>
<input type="hidden"><xsl:attribute name="value">$<xsl:value-of select="StandardPrice" />,</xsl:attribute><xsl:attribute name="name">Qty_<xsl:value-of select="position()" /></xsl:attribute></input>
</td>
</tr>
</xsl:if>
</xsl:for-each>
Thanks for your help.
|