Retrieve and compare selected checkbox list values in xslt?
Hi all, I have a doc type with a property consisting of a datatype that has a checkbox list for its render control. Just wondering how do I retrieve and compare the selected checkbox list values in xslt? I basically want to select & loop through all nodes that have a certain checkbox value selected.
In your checkbox...should it be possible to select more than one value or is your intention that it should only be possible to select one value? The solution depens a bit on that I think.
Hi Jan, I've got 3 sites within the one umbraco installation and then I've also got a 'news item' doc type. I've added a property to this doc type that is a checkbox list that allows the user to specify which site the news item should appear on. The property name is 'News Site'.
The 3 checkbox values are:
Site 1: 5 Site 2: 6 Site 3: 7
Then on the home page of each site I only want to list news items that have the corresponding checkbox selected (I've put the part in bold that I'm trying to do):
Thanks for such post which is very helpful... I am also doing the same thing as jonok, but in my case when we select the sites checkbox list, it by default stores the values of selectedf checkbox but I want to store the ids of selected checkbox... can any body tell me how to change the default property to dave IDs instead of Values....
Retrieve and compare selected checkbox list values in xslt?
Hi all, I have a doc type with a property consisting of a datatype that has a checkbox list for its render control. Just wondering how do I retrieve and compare the selected checkbox list values in xslt? I basically want to select & loop through all nodes that have a certain checkbox value selected.
Thanks.
Hi
In your checkbox...should it be possible to select more than one value or is your intention that it should only be possible to select one value? The solution depens a bit on that I think.
Hi Jan, I've got 3 sites within the one umbraco installation and then I've also got a 'news item' doc type. I've added a property to this doc type that is a checkbox list that allows the user to specify which site the news item should appear on. The property name is 'News Site'.
The 3 checkbox values are:
Site 1: 5
Site 2: 6
Site 3: 7
Then on the home page of each site I only want to list news items that have the corresponding checkbox selected (I've put the part in bold that I'm trying to do):
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="$currentPage/ancestor-or-self::node [@level=1]/@id = 1048">
<xsl:call-template name="renderNews">
</xsl:call-template>
</xsl:when>
<xsl:when test="$currentPage/ancestor-or-self::node [@level=1]/@id = 1056">
<xsl:call-template name="renderNews">
</xsl:call-template>
</xsl:when>
<xsl:when test="$currentPage/ancestor-or-self::node [@level=1]/@id = 1063">
<xsl:call-template name="renderNews">
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="renderNews">
<xsl:param name="site"/>
news <xsl:value-of select="$site" />
<xsl:for-each select="umbraco.library:GetXmlAll()//node [@nodeTypeAlias = 'News Item' and string(data [@alias='umbracoNaviHide']) != '1' and @SiteNews = $site]">
<div>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</div>
</xsl:for-each>
</xsl:template>
Ok - Try changing the highlighted part to this data[@alias ='SiteNews']=$site - I think that should work.
So the whole line looks like this instead.
<xsl:for-each select="umbraco.library:GetXmlAll()//node [@nodeTypeAlias = 'News Item' and string(data [@alias='umbracoNaviHide']) != '1' and data [@alias = 'SiteNews' ]= $site]">
/Jan
Thats nearly it Jan, I can now see the selected checkbox values for each news item. When I do this...
<xsl:value-of select="data [@alias = 'SiteNews']"/>
...I get a comma separated list of the checkbox titles which is good, but then I need something similar to a string.contains function or something...
<xsl:for-each select="umbraco.library:GetXmlAll()//node [@nodeTypeAlias = 'News Item' and string(data [@alias='umbracoNaviHide']) != '1'<span style="white-space: pre-wrap;"> <strong style="white-space: pre-wrap; word-wrap: break-word;">and data [@alias = 'SiteNews' ]]"></span>
sorry, that last piece of code is meant to look like this:
<xsl:for-each select="umbraco.library:GetXmlAll()//node [@nodeTypeAlias = 'News Item' and string(data [@alias='umbracoNaviHide']) != '1' and data [@alias = 'SiteNews' ].Contains($site)]">
There is a built in contains function in xslt:
http://www.zvon.org/xxl/XSLTreference/Output/function_contains.html
Thanks for the help, much appreciated.
Hi,
Thanks for such post which is very helpful... I am also doing the same thing as jonok, but in my case when we select the sites checkbox list, it by default stores the values of selectedf checkbox but I want to store the ids of selected checkbox... can any body tell me how to change the default property to dave IDs instead of Values....
is working on a reply...