Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Chuck 71 posts 69 karma points
    Feb 11, 2011 @ 15:41
    Chuck
    0

    dynamic for-each select statement

    I need to list products based on a series of checkboxes that the user has selected. I already have a variable that contains the checked checkboxes, however I am stuck. How do I take this variable that contains this array and use it to generate a custom select statement for generating my products list?

    I have a for-each that looks like this.   

    <xsl:for-each select="$theCheckboxes [string(umbraco.library:RequestForm(@alias)) = @alias]">

        <xsl:value-of select="@alias"/><br/>

    </xsl:for-each>

    this lists out my aliases which looks like this
    alias1
    alias4
    alias7

    how do I take this array and create a select statement that looks like this?

    <xsl:for-each select="$products/* [@isDoc and alias1='1' and alias4='1' and alias 7='1']">

     

    Thanks,
    Chuck

  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    Feb 11, 2011 @ 19:23
    Casey Neehouse
    1

    Well Chuck, this is a fun one to deal with...  Dynamic is not possible, however, the result you want is possible.

    First, lets capture all the selected checkboxes into a variable.

    <xsl:variable name="selectedCheckboxes">,
        <xsl:for-each select="$theCheckboxes [string(umbraco.library:RequestForm(@alias)) = @alias]">
            <xsl:value-of select="@alias"/>,
        </xsl:for-each>
    </xsl:variable>

    (I remove line breaks and spaces to make it work flawlessly)

    Now your for each needs to get products that match the selected checkboxes completely, and also returns other checked items on the product that aren't part of the criteria.  The result is that you need to count the nodes that don't match your criteria.

    • The property is checked and in the selected Checkboxes list,
    • The property is checked and not in the selected Checkboxes list,
    • The property is not checked, and not in the Checkboxes list,
    • and we don't want the property is not checked, and is in the checkboxes list.

    Thus, if we have any #4 items, we want to ignore the product.

    So, we count the false properties, and if we have a count greater than 0, we fail the product.

    <xsl:for-each select="$products/* [@isDoc
                 and count(node()[not(text()='1' or not(contains($selectedCheckboxes, concat(',',local-name(),','))))] ) = 0
                ]">

     

  • Chuck 71 posts 69 karma points
    Feb 11, 2011 @ 22:21
    Chuck
    0

    Thanks Casey, this indeed worked. here is my script for future reference.

    <xsl:variable name="selectedCheckboxes">,<xsl:for-each select="$theCheckboxes [string(umbraco.library:Request(@alias)) = @alias]">        <xsl:value-of select="@alias"/>,</xsl:for-each></xsl:variable>

    <xsl:variable name="products" select="umbraco.library:GetXmlNodeById($searchNode)/* [@isDoc and count(node()[not(text()='1' or not(contains($selectedCheckboxes, concat(',',local-name(),','))))] ) = 0]"/>

    <xsl:for-each select="$products">

     

    </xsl:for-each>

    Works like a charm! And brilliant! I owe you a fruit basket! Thank you so much!


     


Please Sign in or register to post replies

Write your reply to:

Draft