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...
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 :-)
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>
<!-- 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.
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>
<!-- 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>
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:
This works if only one box is checked on the listing page but not if more than one is checked...
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
OR
Yes, comma seperated values from the built in checkbox datatype
no, strings
Hi Claus,
I always try to break these down into "puzzle parts", so here's how I'd approach it:
/Chriztian
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? ",',")
But it doesnt render anything doing this...
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
- And that would be something like this:
- But this approach will get you duplicates, which the other (if working) wouldn't. Sets are awesome in that way.
/Chriztian
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...
Hi Claus,
This should be so close to the goal that you can hear the ball... :-)
/Chriztian
Cool It seems to do the trick, To sum it up:
is working on a reply...