Copied to clipboard

Flag this post as spam?

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


  • jonok 297 posts 658 karma points
    Jul 13, 2009 @ 15:19
    jonok
    0

    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.

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 13, 2009 @ 16:36
    Jan Skovgaard
    0

    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.

  • jonok 297 posts 658 karma points
    Jul 13, 2009 @ 17:23
    jonok
    0

    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>

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 13, 2009 @ 17:48
    Jan Skovgaard
    100

    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

  • jonok 297 posts 658 karma points
    Jul 13, 2009 @ 18:56
    jonok
    0

    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>

     

  • jonok 297 posts 658 karma points
    Jul 13, 2009 @ 18:57
    jonok
    0

    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)]">

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Jul 13, 2009 @ 19:49
    Morten Bock
    2

    There is a built in contains function in xslt:

    http://www.zvon.org/xxl/XSLTreference/Output/function_contains.html

    <xsl:for-each select="umbraco.library:GetXmlAll()//node [@nodeTypeAlias = 'News Item' and string(data [@alias='umbracoNaviHide']) != '1' and contains(data [@alias = 'SiteNews' ], $site)]">

     

  • jonok 297 posts 658 karma points
    Jul 13, 2009 @ 22:26
    jonok
    0

    Thanks for the help, much appreciated.

  • Faheem Habib 5 posts 25 karma points
    Nov 29, 2012 @ 09:59
    Faheem Habib
    0

    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....

Please Sign in or register to post replies

Write your reply to:

Draft