简体   繁体   English

Umbraco XSLT计算多个文本字符串中第一个值的媒体属性

[英]Umbraco 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. 该属性使用“多个文本字符串”数据类型,每个文本字符串包含三个值,中间用逗号分隔媒体ID,版本号以及添加的日期和时间。

eg 1475,1,28-Dec-12 01:26:45 (Media ID,version number,date and time added) 例如1475,1,28-Dec-12 01:26:45(媒体ID,版本号,添加的日期和时间)

The first value is the media ID, on that mediatype I have a "protectedFile" true/false property. 第一个值是媒体ID,在该媒体类型上,我具有“ protectedFile” true / false属性。 I want to count how many of the items in my list of multiple textstrings have that value set to "true" 我想计算我的多个文本字符串列表中有多少个项目将该值设置为“ 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 但是由于它是“ for-each”的结果显示为:受保护的文件:111

I need it to display as a count Protected file: 3 我需要将其显示为计数受保护的文件:3

Can anybody assist me? 有人可以帮助我吗?

Cheers, JV 欢呼声,合资企业

In order to do adding/substracting/etc in XSLT you need to use recursion. 为了在XSLT中添加/减去/等,您需要使用递归。 That's done using xsl:call-template and having a secondary xsl:template that is like a function. 这是使用xsl:call-template并具有一个类似于函数的辅助xsl:template来完成的。 Something like this is a simple example: 这样的例子很简单:

<xsl:variable name="incrementVal" select="1"/>

<xsl:template match="/">

  <xsl:call-template name="addLoop">
    <xsl:with-param name="inc" select="$incrementVal" />
    <xsl:with-param name="count" select="5" />
  </xsl:call-template>

</xsl:template>

<xsl:template name="addLoop">
  <xsl:param name="inc" />
  <xsl:param name="count" />

  <xsl:choose>
    <xsl:when test="$count = 0">
      <xsl:value-of select="$inc"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:call-template name="addLoop">
        <xsl:with-param name="inc" select="$inc + 1" />
        <xsl:with-param name="count" select="$count - 1" />
      </xsl:call-template>
    </xsl:otherwise>
  </xsl:choose>

</xsl:template>

Put that in a test XSLT and use the XSLT test tool to see the result. 将其放入测试XSLT中,然后使用XSLT测试工具查看结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM