Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #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.


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 05: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 07:46 AM



All times are GMT -4. The time now is 05:28 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.