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
    Jan 08, 2013 @ 07:37
    syn-rg
    0

    XSLT count media property of first value in multiple textstring

    I'm creating a macro that sources a property from the current member. The property uses the "multiple textstrings" datatype, and each textstring contains three values separated by commas a media ID, the version number and the date and time added.

    e.g. 1475,1,28-Dec-12 01:26:45 (Media ID,version number,date and time added)

    The first value is the media ID, on that mediatype I have a "protectedFile" true/false property. I want to count how many of the items in my list of multiple textstrings have that value set to "true"

    I've tried the following to count all "protectedFiles" but without luck:

    <h3>Protect files:
                <xsl:variable name="contentSplit" select="umbraco.library:Split(current(), ',')" />
                <xsl:value-of select="count(umbraco.library:GetCurrentMember()/assetDownloads/values/contentSplit/value[position() = 1 and umbraco.library:GetMedia(., 0)/protectedFile != '0'])"/>
    
            </h3>
    
            <!-- List all values -->
            <ul>
                <xsl:for-each select="umbraco.library:GetCurrentMember()/assetDownloads/values/value">
                    <li>
    
                        <!-- Split values via , comma using below function -->
                        <xsl:variable name="contentSplit" select="umbraco.library:Split(current(), ',')" />
    
                        <xsl:for-each select="$contentSplit/value">
    
                            <!-- First value as preview image and nodeName -->
                            <xsl:if test="position() = 1">
                                <img>
                                    <xsl:attribute name="src">
                                        <xsl:value-of select="umbraco.library:GetMedia(., 0)/preview" />
                                    </xsl:attribute>
                                </img>
                                <p><xsl:value-of select="umbraco.library:GetMedia(., 0)/@nodeName" /></p>
    
                                <xsl:if test="umbraco.library:GetMedia(., 0)/protectedFile != '0'">
                                    <p><xsl:value-of select="umbraco.library:GetMedia(., 0)/protectedFile" /></p>
                                </xsl:if>
                            </xsl:if>
    
                            <!-- Second value as version number -->
                            <xsl:if test="position() = 2">
                                <p>
                                    Version: <xsl:value-of select="." />
                                </p>
                            </xsl:if>
    
                            <!-- Third value as date and time of download -->
                            <xsl:if test="position() = 3">
                                <p>
                                    Date Time: <xsl:value-of select="." />
                                </p>
                            </xsl:if>
    
                        </xsl:for-each>
    
                    </li>
                </xsl:for-each>
            </ul>

    Can anybody assist me?

    Cheers, JV

  • John C Scott 473 posts 1183 karma points
    Jan 08, 2013 @ 09:57
    John C Scott
    0

    i've been looking at this for a little while and I haven't seen an answer yet

    i had a question though if that's ok?

    does the for-each loop "List-all-values" work ok ? is it only the count you have the problem with ?

    also looping inside this for the position

     

    <xsl:for-eachselect="$contentSplit/value">
    <xsl:iftest="position() = 1">

     

    etc.. with the test felt wrong, could this be done as 

     

    <xsl:value-ofselect="umbraco.library:GetMedia($contentSplit/value[1], 0)/preview"/>

     

    i know that's not the issue, I just wondered really? :) 

    but this all works ok as it is ?

     

    but with regard to the count

    <xsl:value-ofselect="count(umbraco.library:GetCurrentMember()/assetDownloads/values/contentSplit/value[position() = 1 and umbraco.library:GetMedia(., 0)/protectedFile != '0'])"/>

     i suspect the GetMedia(.) I'm not sure but I can't see how this would be the current - my thoughts and approach next would be to ouput this without the count and see what you are getting in this xpath selection

  • Charles Afford 1163 posts 1709 karma points
    Jan 08, 2013 @ 22:40
    Charles Afford
    0

    Hello,  Take a look at this post (the bit right at the bottom).  http://our.umbraco.org/forum/developers/xslt/37317-Comma-separated-multiple-textstrings-list  I belive he is doing the same sort of thing.  Trying to split comma delimited string.  Charles (did not realise it was the same person :P)

  • syn-rg 282 posts 425 karma points
    Jan 09, 2013 @ 00:48
    syn-rg
    0

    Thanks John C Scott, my code for the "List all values" is working.

    I've made the following variable:

    <xsl:variable name="protectedFile">
        <xsl:for-each select="umbraco.library:GetCurrentMember()/assetDownloads/values/value">
            <xsl:variable name="contentSplit" select="umbraco.library:Split(current(), ',')" />
            <xsl:for-each select="$contentSplit/value">
                <xsl:if test="position() = 1">
                    <xsl:if test="umbraco.library:GetMedia(., 0)/protectedFile != '0'">
                        <xsl:value-of select="umbraco.library:GetMedia(., 0)/protectedFile" />
                    </xsl:if>
                </xsl:if>
            </xsl:for-each>
        </xsl:for-each>
    </xsl:variable>
    
    <h3>Protected file: <xsl:value-of select="$protectedFile"/></h3>

    But as it's a "for-each" the result is displayed as:
    Protected file: 111 

    I need it to display as a count. e.g Protected file: 3

  • John C Scott 473 posts 1183 karma points
    Jan 10, 2013 @ 01:16
    John C Scott
    0

    i've been thinking about this a lot

    i have a few ideas but sadly no time to type them up

    could skype? http://c3x.co/contact tomorrow?

     

     

Please Sign in or register to post replies

Write your reply to:

Draft