开发者

How to increment a variable inside an XSLT template?

here is briefly the problem I'm facing:

I have built a custom Content Query webpart, I fill this CQWP with items from a list. What I would like to do is to have a special separator each 3 items.

How to tell the XSLT that the current item is the 3, 6 or 9th one, and therefore, that a separator has to be put ?

what I have thought of would be to do something like that in the itemstyle.xsl:

<xsl:va开发者_如何学JAVAriable name="increment" select="0"/>
<xsl:template>
<xsl:with-variable name="increment" select="$increment+1"/>
<xsl:if increment = multiple de 3>
-put a separator-
</xsl:if>
</xsl:template>

but it appears that global variable cannot be used this way. Therefore my second idea would to get sortof the "row number" of the corresponding item in order to get the same information.

Does anybody have any idea of how I can solve this problem ?


XSLT does not do destructive update. Therefore you cannot assign a value to a variable and then overwrite the variable with a new value later.

In your case, you can use the position() function with modulus arithmetic:

<xsl:for-each select="*">
  <!-- normal processing here -->
  <xsl:if test="position() mod 3 = 0">
    <!-- separator here -->
  </xsl:if>
</xsl:for-each>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜