Copied to clipboard

Flag this post as spam?

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


  • Rik Helsen 670 posts 873 karma points
    Oct 12, 2010 @ 18:52
    Rik Helsen
    0

    Listing unique values from a set of listcheckboxes

    I have a list of subpages that each have a checkboxlist (0-10) to indicate what floor an appartement is on. Appartments can be on multiple floors (duplexes)

    I need to get all the pages and their "floor" property, and list all the floors where there are appartments available...once...

    $unfiltered returns: 0,0,1,1,1,2,2,3,4,5,5,6,5,6,6,6

    $sortedunfiltered returns: 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 5, 6, 6, 6,

    Can anyone help me reduce this serie to a distinct list ?

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
        exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>
    <xsl:template match="/">

    <!-- The fun starts here -->
    <xsl:variable name="unfiltered">
        <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
        <xsl:value-of select="data [@alias = 'floor']"/>
            <xsl:if test="position()!=last()">,</xsl:if>
        </xsl:for-each>
    </xsl:variable>

    <xsl:value-of select="$sortedunfiltered"/>

    <xsl:variable name="unfilteredarray">
        <xsl:for-each select="Exslt.ExsltStrings:tokenize($unfiltered, ',')">
        <xsl:sort select="." order="ascending"/>
            <xsl:value-of select="."/>,       
        </xsl:for-each>
    </xsl:variable>


    </xsl:template>
    </xsl:stylesheet>
  • Nik Wahlberg 639 posts 1237 karma points MVP
    Oct 12, 2010 @ 19:02
    Nik Wahlberg
    0

    Hi there, I would take a look at using the umbraco.library.Split() function for this. Here's an example. 

    <xsl:variable name="sortedUnfilteredArray" select="umbraco.library:Split($currentPage/clientList, ',')" />

    Then use this to loop over the list...

    <xsl:for-each select="$sortedUnfilteredArray/value"><xsl:value-of select="." /></xsl:for-each>

    HTH,
    Nik

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Oct 12, 2010 @ 19:03
    Nik Wahlberg
    0

    Ooops, read your question wrong I think...gimme a sec. Sorry. 

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Oct 12, 2010 @ 19:07
    Nik Wahlberg
    0

    You may need to do this in an extension method as there is no way to create an incremental variable in XSLT, Let us know if you need an example on that. Sorry about cluttering your post/question. 

    Thanks,
    Nik

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 12, 2010 @ 21:30
    Chriztian Steinmeier
    1

    Hi Rik,

    You can do something like this:

       <xsl:variable name="unfilteredtokens">
            <tokens>
                <xsl:for-each select="Exslt.ExsltStrings:tokenize($unfiltered, ',')">
                <xsl:sort select="." order="ascending"/>
                    <xsl:copy-of select="." />        
                </xsl:for-each>       
            </tokens>
        </xsl:variable>
        <xsl:variable name="unfilteredset" select="msxml:node-set($unfilteredtokens)/tokens" />
    
        <ul>
            <xsl:for-each select="$unfilteredtokens[not(. = following-sibling::*[1])]">
                <li><xsl:value-of select="." /></li>
            </xsl:for-each>
        </ul>
    
    Instead of an array, build a sorted node-set of the values ('token' elements) and then pick only the ones that arent' immediately followed by an identical value...
    Hope it makes sense,

    /Chriztian

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Oct 12, 2010 @ 21:34
    Nik Wahlberg
    0

    Nice! That is a great solution. Never thought to use node-set for this sort of thing. 

  • Rik Helsen 670 posts 873 karma points
    Oct 13, 2010 @ 09:59
    Rik Helsen
    0

    Thanks a lot!

    resulting xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>
    <xsl:template match="/">

    <!-- The fun starts here -->
    <xsl:variable name="unfiltered">
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1' and @nodeTypeAlias = 'Appartment']">
    <xsl:value-of select="data [@alias = 'floor']"/>
    <xsl:if test="position()!=last()">,</xsl:if>
    </xsl:for-each>
    </xsl:variable>
    <xsl:variable name="unfilteredtokens">
    <tokens>
    <xsl:for-each select="Exslt.ExsltStrings:tokenize($unfiltered, ',')">
    <token>
    <xsl:copy-of select="." />
    </token>
    </xsl:for-each>
    </tokens>
    </xsl:variable>
    <xsl:variable name="unfilteredset" select="msxml:node-set($unfilteredtokens)/tokens/token" />
    <ul>
    <xsl:for-each select="$unfilteredset[not(. = following-sibling::*[1])]">

    <li><a href="{umbraco.library:NiceUrl($currentPage/@id)}"><xsl:value-of select="." /></a></li>
    </xsl:for-each>
    </ul>
    </xsl:template>
    </xsl:stylesheet>
Please Sign in or register to post replies

Write your reply to:

Draft