增量在XSLT 1.0中for-each中的变量计数

时间:2014-11-26 10:53:40

标签: xslt

我想在for-each循环中增加变量。这是我的代码。

<xsl:variable name="i" select="1" />
<xsl:variable name="oddEven" select="1" />
<xsl:for-each select="//ProfileBR">
    <xsl:variable name="j" select="$i + 1" />
    sharad j :: <xsl:value-of select="$j"></xsl:value-of>
    <xsl:variable name="iBR" select="substring(//BRValue,$i,1)" />
    <xsl:variable name="jBR" select="substring(//BRValue,$j,1)" />
    <xsl:if test="$iBR='1' or $jBR='1'">
        <xsl:choose>
            <xsl:when test="$oddEven='1'">
                <tr class="sbListOddCell">
                    <xsl:call-template name="JobInfoSection">
                        <xsl:with-param name="ii" select="$i"/>
                        <xsl:with-param name="jj" select="$j"/>
                        <xsl:with-param name="iiBR" select="$iBR"/>
                        <xsl:with-param name="jjBR" select="$jBR"/>
                    </xsl:call-template>
                </tr>
                <xsl:variable name="oddEven" select="0" />
            </xsl:when>
            <xsl:otherwise>
                <tr class="sbListEvenCell">
                    <xsl:call-template name="JobInfoSection">
                        <xsl:with-param name="ii" select="$i"/>
                        <xsl:with-param name="jj" select="$j"/>
                        <xsl:with-param name="iiBR" select="$iBR"/>
                        <xsl:with-param name="jjBR" select="$jBR"/>
                    </xsl:call-template>
                </tr>
                <xsl:variable name="oddEven" select="1" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:if>
    <xsl:variable name="i" select="$j + 1" />
</xsl:for-each>

我希望在每次迭代中增加i和j,但在每次迭代后分别以3和2结束。

如何增加i和j。

谢谢, 沙拉德帕

1 个答案:

答案 0 :(得分:0)

使用position()来获取for-each中迭代的计数:

<xsl:variable name="j" select="$i + position()" />