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>
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
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:
Can anybody assist me?
Cheers, JV
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
etc.. with the test felt wrong, could this be done as
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
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
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)
Thanks John C Scott, my code for the "List all values" is working.
I've made the following variable:
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
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?
is working on a reply...