Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 886 posts 2415 karma points
    Aug 03, 2012 @ 11:09
    Claushingebjerg
    0

    Matching two checkbox lists

    Im trying to match values for two checkbox lists, but i cant quite get to work. Its an older site, so im working in old schema.

    I have a list of nodes. On each of them i have a check box list data type, where the user can select 

    option 1
    option 2
    option 3
    option 4

    I then have a page that lists the nodes. On this page i have the same data type. If i want the list to contain only nodes with option 1 and option 2, i check only these...

    Hope it makes sense.

    I have the following code:

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/node [string(data [@alias='umbracoNaviHide']) != '1' and contains (data [@alias = 'reftype'], $currentPage/data [@alias = 'reftype'])]">

     

    This works if only one box is checked on the listing page but not if more than one is checked...

     

     

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Aug 03, 2012 @ 11:18
    Chriztian Steinmeier
    0

    Hi Claus,

    If you check 1 and 2 on the listing page, do you want pages that have both of these checked (AND), or pages that have either checked (OR) ?

    They're stored as a comma-separated list of values, right?

    Are they node ids?

    /Chriztian

  • Claushingebjerg 886 posts 2415 karma points
    Aug 03, 2012 @ 11:23
    Claushingebjerg
    0

    OR

    Yes, comma seperated values from the built in checkbox datatype

    no, strings

     

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Aug 03, 2012 @ 11:33
    Chriztian Steinmeier
    0

    Hi Claus,

    I always try to break these down into "puzzle parts", so here's how I'd approach it:

    <!-- Simpler access to the nodes we need to filter -->
    <xsl:variable name="possibleNodes" select="umbraco.library:GetXmlNodeById($source)/node[not(data[@alias = 'umbracoNaviHide'] = 1)]" />
    
    <!-- List of types we want to find -->
    <xsl:variable name="refTypesToShow" select="umbraco.library:Split($currentPage/data[@alias = 'reftype'])" />
    
    <!-- Now find them (this *may* not work - may need to do a for-each on $refTypesToShow/value instead) -->
    <xsl:variable name="nodesToShow" select="$possibleNodes[contains(data[@alias = 'reftype'], $refTypesToShow/value)]" />
    
    - The old schema really doesn't help in making this readable :-)

    /Chriztian 

  • Claushingebjerg 886 posts 2415 karma points
    Aug 03, 2012 @ 11:54
    Claushingebjerg
    0

    Ok, so to bring it a step further i the puzzle, my intuition tells me something like this: (btw, you have to supply a 'split by' character, dont you? ",',")

    <!-- Simpler access to the nodes we need to filter -->
    <xsl:variable name="possibleNodes" select="umbraco.library:GetXmlNodeById($source)/node[not(data[@alias = 'umbracoNaviHide'] = 1)]"/>

    <!-- List of types we want to find -->
    <xsl:variable name="refTypesToShow" select="umbraco.library:Split($currentPage/data[@alias = 'reftype'],',')"/>

    <!-- Now find them (this *may* not work - may need to do a for-each on $refTypesToShow/value instead) -->
    <xsl:variable name="nodesToShow" select="$possibleNodes[contains(data[@alias = 'reftype'], $refTypesToShow/value)]"/>

    <!-- Liting the nodes -->
    <xsl:for-each select="nodesToShow/node">
    <xsl:value-of select="@nodeName"/>
    </xsl:for-each> 

    But it doesnt render anything doing this...

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Aug 03, 2012 @ 12:00
    Chriztian Steinmeier
    0

    Ha - yes you do - good catch :-)

    You should strip the /node part from the for-each - $nodesToShow is a set of all the matching nodes at that point:

    <!-- Listing the nodes -->
    <xsl:for-eachselect="$nodesToShow">
    <xsl:value-ofselect="@nodeName"/>
    </xsl:for-each>

    If this doesn't do it, we need to do it a little backwards (the C# way :-) and run through the $refTypesToShow values...

    /Chriztian 

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Aug 03, 2012 @ 12:06
    Chriztian Steinmeier
    0

    - And that would be something like this:

    <!-- Run through the list of values requested, listing nodes that match -->
    <xsl:for-each select="$refTypesToShow/value">
        <xsl:variable name="nodesWithThisValue" select="$possibleNodes[contains(data[@alias = 'reftype'], current())]" />
    
        <h2><xsl:value-of select="." /></h2>
    
        <xsl:for-each select="$nodesWithThisValue">
            <p><xsl:value-of select="@nodeName" /></p>
        </xsl:for-each>
    
    </xsl:for-each>

    - But this approach will get you duplicates, which the other (if working) wouldn't. Sets are awesome in that way.

    /Chriztian

  • Claushingebjerg 886 posts 2415 karma points
    Aug 03, 2012 @ 13:17
    Claushingebjerg
    0

    Ok, so approach 2 works, but splits the list in segments with duplicates, as you mentioned...

    How do we fix that? I really just need one long list without duplicates...

     

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Aug 03, 2012 @ 13:30
    Chriztian Steinmeier
    1

    Hi Claus,

    This should be so close to the goal that you can hear the ball... :-)

    <!-- Create an XML variable of <nodeId> elements -->
    <xsl:variable name="nodesProxy">
        <xsl:for-each select="$refTypesToShow/value">
            <xsl:for-each select="$possibleNodes[contains(data[@alias = 'reftype'], current())]">
                <nodeId><xsl:value-of select="@id" /></nodeId>
            </xsl:for-each>
        </xsl:for-each>
    </xsl:variable>
    <!-- Make XPath navigation in the variable possible -->
    <xsl:variable name="nodeIds" select="msxml:node-set($nodesProxy)" />
    
    <!-- Run through the set of nodes that have a nodeid in the set of ids -->
    <xsl:for-each select="$possibleNodes[@id = $nodeIds/nodeId]">
        <p>
            <xsl:value-of select="@nodeName" />
        </p>
    </xsl:for-each>
    

    /Chriztian

  • Claushingebjerg 886 posts 2415 karma points
    Aug 03, 2012 @ 13:42
    Claushingebjerg
    1

    Cool It seems to do the trick, To sum it up:

    <!-- Access to the nodes we need to filter -->
    <xsl:variable name="possibleNodes" select="umbraco.library:GetXmlNodeById($source)/node[not(data[@alias = 'umbracoNaviHide'] = 1)]" />

    <!-- List of types we want to find -->
    <xsl:variable name="refTypesToShow" select="umbraco.library:Split($currentPage/data[@alias = 'reftype'],',')" />

    <!-- Create an XML variable of <nodeId> elements --> <xsl:variable name="nodesProxy"> <xsl:for-each select="$refTypesToShow/value"> <xsl:for-each select="$possibleNodes[contains(data[@alias = 'reftype'], current())]"> <nodeId><xsl:value-of select="@id" /></nodeId> </xsl:for-each> </xsl:for-each> </xsl:variable> <!-- Make XPath navigation in the variable possible --> <xsl:variable name="nodeIds" select="msxml:node-set($nodesProxy)" /> <!-- Run through the set of nodes that have a nodeid in the set of ids --> <xsl:for-each select="$possibleNodes[@id = $nodeIds/nodeId]"> <p> <xsl:value-of select="@nodeName" /> </p> </xsl:for-each>

     

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies