如何根据每个循环计数动态设置元素值

时间:2012-07-10 20:26:14

标签: foreach xslt

这是我正在努力工作的xsl文件的片段。

我想根据Body中的循环计数更改标题中元素request-tot-queries的值。非常感谢您的帮助!

<HEADER>
  <request-tot-queries>$Counter</request-tot-queries>
</HEADER>
<Body>
 <xsl:for-each select="//Request/Responses/Pooled/ResidenceHistory/Residencies/Residency">
 <count><xsl:variable name="counter" select="position()"/></count>
  <xsl:if test="DateRange/To/Date[@Type!='Present']">
   <subject-query>
      .
      .
      .
   </subject-query>
  </xsl:if>
 </xsl:for-each>
</Body>

1 个答案:

答案 0 :(得分:1)

使用count()功能:

<HEADER>
  <request-tot-queries>
    <xsl:value-of select="count(//Request/Responses/Pooled/ResidenceHistory/Residencies/Residency)"/>
  </request-tot-queries>
</HEADER>