【问题标题】:Counter in For Loop of XSLTXSLT 的 For 循环中的计数器
【发布时间】:2020-06-26 19:46:57
【问题描述】:

我正在全局声明一个变量,并希望在带有 IF 条件的 for 循环中递增。然后稍后想在最后的 XSLT 的 Trailer 记录中使用该变量。

0 - 全局声明

<xsl:for-each>
  <xsl:if test="../xyz">
    <WorkerBen>

    <I need to increment a variable BENCountV here once above condition is met>
                    
   </WorkerBEN>
 </xsl:if>                      
</xsl:for-each> 

【问题讨论】:

  • 请发布minimal reproducible example 显示输入和预期输出。
  • 在 xslt 中,不需要 for 循环来实现:您只需将变量设置为 &lt;xsl:variable name="BENCountV" select="count(yourXpath[yourCondition])"/&gt;

标签: xslt counter


【解决方案1】:

将变量绑定到所选项目:

<xsl:variable name="items" select="xxx[../xyz]"/>

遍历它们:

<xsl:for-each select="$items">...</xsl:for-each>

然后数一数:

<xsl:value-of select="count($items)"/>

【讨论】:

  • 谢谢迈克尔。我想根据循环内的 IF 条件进行计数,然后在循环外使用该值。
  • 如果您向我们展示输入和所需的输出,那么我们可以向您展示正确的方法,这与您在程序语言中的操作方式完全不同。你的想法太程序化了。
猜你喜欢
  • 1970-01-01
  • 2020-05-31
  • 1970-01-01
  • 2010-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多