Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 10th, 2006, 07:20 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Do Loop stealthdevil Access VBA 5 October 5th, 2006 01:22 PM
Do Until loop with IF crmpicco Classic ASP Databases 2 June 15th, 2005 05:35 PM
For....Loop kliu9 Excel VBA 5 February 10th, 2005 06:43 AM
Do Loop junemo Beginning PHP 8 July 28th, 2004 02:58 AM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.