Results 1 to 4 of 4

Thread: Nested for-each XSL Loops

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Location
    Hertfordshire
    Posts
    12

    Unhappy Nested for-each XSL Loops

    Is it possible to have nested <xsl:for-each> loops within an xsl stylesheet?

    I'm trying to get two rows of 12 buttons to appear on a web-page to simulate the F1 thru F24 and the ENTER button. I have the following code within my Stylesheet:

    <table border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td><input type="SUBMIT" name="NEEPFNAME" value="ENTR" /></td>
    <xsl:for-each select='PFNEWLINE'>
    </tr>
    <tr>
    <xsl:for-each select='PFKEY'>
    <td>
    <xsl:variable name="PFTYPE" select="PFTYPE" />
    <xsl:variable name="PFVALUE" select="PFVALUE" />
    <xsl:variable name="PFHEKEY" select="PFHEKEY" />
    <xsl:variable name="PFNUM" select="PFNUM" />
    <input type="{$PFTYPE}" name="NEEPFNAME" value="{$PFVALUE}" np=" KEY={$PFNUM} {$PFHEKEY} " >
    <xsl:if test="PFDISABLED = 'DISABLED'">
    <xsl:attribute name="DISABLED" />
    </xsl:if>
    </input>
    </td>
    </xsl:for-each>
    </xsl:for-each>
    </tr>
    <tr>
    <td></td>
    </tr>
    </table>

    The XML I pass into this stylesheet is as follows:
    <PFNEWLINE>
    <PFKEY>
    <PFTYPE>SUBMIT</PFTYPE>
    <PFVALUE>Help</PFVALUE>
    <PFHEKEY>hekey=T</PFHEKEY>
    <PFDISABLED></PFDISABLED>
    <PFNUM>PF1</PFNUM>
    </PFKEY>
    <PFKEY> [Repeated a total of 12 times]
    </PFNEWLINE
    [Above PFNEWLINE block repeated twice]


    When I try to run my app to produce the web-page it falls over saying that there is something wrong near the </tr> tag of the PFNEWLINE for-each statement.

    Can anyone help?
    'Audere est facere'

    VB5 (Beginner/Intermediate)
    SQL
    C#

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    <xsl:for-each select='PFNEWLINE'>

    shouldnt you be using double quotes?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Try this:
    Code:
    <table border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td><input type="SUBMIT" name="NEEPFNAME" value="ENTR" /></td>
    </tr>
    <xsl:for-each select='PFNEWLINE'>
    <tr>
    <xsl:for-each select='PFKEY'>
    <td>
    <xsl:variable name="PFTYPE" select="PFTYPE" />
    <xsl:variable name="PFVALUE" select="PFVALUE" />
    <xsl:variable name="PFHEKEY" select="PFHEKEY" />
    <xsl:variable name="PFNUM" select="PFNUM" />
    <input type="{$PFTYPE}" name="NEEPFNAME" value="{$PFVALUE}" np=" KEY={$PFNUM} {$PFHEKEY} " >
    <xsl:if test="PFDISABLED = 'DISABLED'">
    <xsl:attribute name="DISABLED" />
    </xsl:if>
    </input>
    </td>
    </xsl:for-each>
    </tr>
    </xsl:for-each>
    <tr>
    <td></td>
    </tr>
    </table>
    I adjusted where the for/each begins & ends in relation to the TR tags...
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Location
    Hertfordshire
    Posts
    12
    Thanks, that works fine.

    Ideally though I wanted the ENTR button on the same line as the first group of PFkeys. I've moved the <tr></tr> tags to try to get this to work, but to no avail.
    'Audere est facere'

    VB5 (Beginner/Intermediate)
    SQL
    C#

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width