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:
<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 Protected file: 3
Can anybody assist me?
Cheers,
JV
In order to do adding/substracting/etc in XSLT you need to use recursion. That’s done using xsl:call-template and having a secondary xsl:template that is like a function. Something like this is a simple example:
Put that in a test XSLT and use the XSLT test tool to see the result.