XSLT:计算循环中案例的迭代次数

XSLT:计算循环中案例的迭代次数,xslt,count,xsl-fo,Xslt,Count,Xsl Fo,我有两个循环,希望计算案例OK和NotOK的迭代次数,以及xslt文件中的总体案例。 我怎么会这么做?如果我想知道这两个迭代的总和,我怎么写呢 我的For循环如下所示: <xsl:for-each select="test"> <xsl:variable name="LinkName" select="attribute::name"/> <tr> <th style="text-al

我有两个循环,希望计算案例
OK
NotOK
的迭代次数,以及
xslt
文件中的总体案例。 我怎么会这么做?如果我想知道这两个迭代的总和,我怎么写呢

我的For循环如下所示:

   <xsl:for-each select="test">
       <xsl:variable name="LinkName" select="attribute::name"/>
           <tr>
              <th style="text-align:left;vertical-align:top;position:"><a name="{$LinkName}"><xsl:value-of select="$LinkName"/></a></th>
                <xsl:for-each select="descendant::node()">
                  <xsl:choose>                                  
                    <xsl:when test="attribute::state='NotOK'">
                        <tr>
                            <td bgcolor="red"><xsl:value-of select="description"/></td>
                        </tr>
                    </xsl:when>
                    <xsl:when test="attribute::state='OK'">
                        <tr>
                            <td bgcolor="lime"><xsl:value-of select="description"/></td>
                        </tr>
                    </xsl:when>
                  </xsl:choose>
                </xsl:for-each>
             </tr>
    </xsl:for-each>

属于
---

对于每个
都不是一个循环。如果要计算
测试
元素的所有子代节点,只需使用
。您还可以向XPath表达式添加谓词,如
count(test/genderant::node()[attribute::state='NotOK'])


内部,上下文节点是一个
test
元素,因此任何计数表达式都应该与该元素相关,例如
count(后代::节点()[attribute::state='NotOK'])

谢谢,请查看我的问题更新版本!我已经添加了提到的行。但是我有所有的零,而我应该有所有的非零数字。如果您在for each中,那么当然需要编写一个相对于上下文节点的表达式。请向我们显示输入和预期输出。您可以通过将
属性::name
更改为
@name
,等等来简化XSLT。如果将
子体::节点()
中的
节点()
更改为具有
@状态的元素的名称,则可以将条件逻辑移动到仅设置
@bgcolor
的值,但是如何最好地编写条件逻辑取决于您使用的XSLT版本。@TonyGraham感谢您的评论。我正在使用版本
1.0
!添加
xsl:attribute
()并将逻辑放入其中,而不是文本
@bgcolor
。如果你需要了解更多,最好开始一个新问题。@martin honnen这样做了。
               <table>
                     <tr bgcolor="coral">
                        <th>Test cases</th>
                        <th>Info</th>
                    </tr>
                    <xsl:for-each select="test">
                        <xsl:variable name="Summation"/>
                        <xsl:variable name="LinkIt" select="@name"/>
                        <xsl:choose>
                            <xsl:when test="descendant::node()/@state='NotOK'">
                                <tr>
                                    <td bgcolor="red"><a href="#{$LinkIt}" title="click for Information"><xsl:value-of select="$LinkIt"/></a></td>
                                    <td>
                                        <xsl:value-of select="count(descendant::node()[@state='NotOK'])"/> of <xsl:value-of select="count(descendant::node()[@state='OK']) + count(descendant::node()[@state='NotOK'])"/>
                                    </td>                                       
                                </tr>
                            </xsl:when>
                            <xsl:when test="descendant::node()/attribute::state='OK'">
                                <tr>
                                    <td bgcolor="lime"><a href="#{$LinkIt}" title="click for Information"><xsl:value-of select="$LinkIt"/></a></td>
                                    <td>
                                        ---
                                    </td>

                                </tr>
                            </xsl:when>
                        </xsl:choose>                           
                    </xsl:for-each>
                </table>