Copied to clipboard

Flag this post as spam?

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


  • syn-rg 282 posts 425 karma points
    Mar 25, 2014 @ 01:09
    syn-rg
    0

    Remove duplicates from for-each list

    I wish to create a list from the multiple media picker.

    Firstly, I select which media items I wish to relate to my page, then create a list of the selected media items. Each media item has a property called "business" which has a value from a dropdown datatype.

    So some of the media items in my list will share the same "business" value. I want remove all duplicates within the list that share the same "business" value.

    I've tried using the following example: http://www.dpawson.co.uk/xsl/sect2/N2696.html

    Manipulating it for my list, but without any success so far. Can someone help me out?

    <xsl:variable name="unique-list" select="$vArr2/value" />   
        <xsl:variable name="unique-list-again" select="$unique-list" />
        <ul>
            <xsl:for-each select="$unique-list-again">
                <xsl:variable name="businessName" select="umbraco.library:GetMedia(., 0)/business"/>
                <xsl:variable name="unique-list" select="$businessName[not(.=following::business)]" />
                <li><xsl:copy-of select="$unique-list" /></li>
            </xsl:for-each>
        </ul>
    
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 25, 2014 @ 09:12
    Chriztian Steinmeier
    0

    Hi JV,

    Are you using the Multi-Node Tree PIcker in Media mode for the "multiple media picker" or are you maybe using the DAMP picker?

    DAMP can save the Media XML, which would make it easier to select based on the business property without having to query the GetMedia() extension for every media item...

    /Chriztian

  • syn-rg 282 posts 425 karma points
    Mar 25, 2014 @ 10:52
    syn-rg
    0

    Hi Chriztian,

    I'm using the Multi media picker in 7.0.3

    Which unfortunately DAMP and uComponents (Multi-Node Tree Picker) aren't available for the Umbraco 7 yet.

    Any other ideas?

    Cheers, JV

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 25, 2014 @ 11:39
    Chriztian Steinmeier
    100

    Okay - that one stores a CSV list of IDs, right?

    Is that what $vArr2 refers to? Did you already Split() the CSV list into nodes?

    You should be able to do something like this (you need to change the PICKER_ALIAS):

    <xsl:template match="/">
        <!-- Collect media referenced in picker -->
        <xsl:variable name="mediaNodesRTF">
            <xsl:for-each select="umbraco.library:Split($currentPage/PICKER_ALIAS, ',')/value">
                <xsl:variable name="node" select="umbraco.library:GetMedia(., false())" />
                <xsl:if test="not($node[error])">
                    <xsl:copy-of select="$node" />
                </xsl:if>
            </xsl:for-each>
        </xsl:variable>
    
        <!-- Convert to XPath-navigable nodeset -->
        <xsl:variable name="mediaNodes" select="msxml:node-set($mediaNodesRTF)" />
    
        <!-- Process those that have a unique `business` value -->
        <xsl:for-each select="$mediaNodes/*[not(business = preceding-sibling::*/business)]">
            <p><xsl:value-of select="@nodeName" /></p>
        </xsl:for-each>
    </xsl:template>
    

    Let me know how i goes,

    UPDATE: Removed extraneous value

    /Chriztian

  • syn-rg 282 posts 425 karma points
    Mar 26, 2014 @ 00:03
    syn-rg
    0

    Cheers, thanks Chriztian! This will come in very handy!

    I just had to make one small change, I removed the extra /value from the for-each:

    <xsl:for-each select="umbraco.library:Split($currentPage/PICKER_ALIAS, ',')/value">
    
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 26, 2014 @ 10:03
    Chriztian Steinmeier
    0

    Ah - of course; - I'll update the code to reflect that.

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft