循环XSL中的索引 [英] index in loop XSL

查看:38
本文介绍了循环XSL中的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XSL中有两个这样的嵌套循环,此刻我使用position(),但这不是我所需要的.

I have two nested loop in XSL like this, at this moment I use position() but it's not what I need.

<xsl:for-each select="abc">
  <xsl:for-each select="def">
   I wanna my variable in here increasing fluently 1,2,3,4,5.....n
not like 1,2,3,1,2,3
  </xsl:for-each>
</xsl:for-each>

您能给我一些关于这个存根的想法吗?非常感谢你!

Can you give me some idea for this stub. Thank you very much!

推荐答案

使用XSL,问题在于您无法更改变量(更像是您要设置的常量).因此,递增计数器变量不起作用.

With XSL, the problem is you cannot change a variable (it's more like a constant that you're setting). So incrementing a counter variable does not work.

一种笨拙的变通方法是获取顺序计数(1,2,3,4,...),将调用position()以获得"abc"标签迭代,而另一个调用position()来获取嵌套的"def"标签迭代.然后,您需要将"abc"迭代乘以其包含的"def"标记的数量.这就是为什么这是一个笨拙"的解决方法.

A clumsy workaround to get a sequential count (1,2,3,4,...) would be to call position() to get the "abc" tag iteration, and another call to position() to get the nested "def" tag iteration. You would then need to multiply the "abc" iteration with the number of "def" tags it contains. That's why this is a "clumsy" workaround.

假设您有两个嵌套的"def"标签,则XSL如下所示:

Assuming you have two nested "def" tags, the XSL would look as follows:

<xsl:for-each select="abc">
    <xsl:variable name="level1Count" select="position() - 1"/>
    <xsl:for-each select="def">
        <xsl:variable name="level2Count" select="$level1Count * 2 + position()"/>
        <xsl:value-of select="$level2Count" />
    </xsl:for-each>
</xsl:for-each>

这篇关于循环XSL中的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆