0

XSL の変数は不変であるという事実を知っています。しかし、私のシナリオでは、グローバル変数をインクリメントし、後でその値を使用したいと考えています。これを行うことができる他の方法はありますか?質問をより明確にするために、コードに十分なコメントを追加しました。XSLT 1.0を使用していることに注意してください

<xsl:variable name="counter">0</xsl:variable>
<xsl:template match="/">
 <xsl:for-each select="Condition_ABC">
  <xsl:variable name="returnValue"> <!--returnValue is the return value from the named template GetValue -->
   <xsl:call-template name="GetValue"/>
  </xsl:variable>
  <xsl:if test="not($returnValue= '')">
   <!-- If the returned value is not null
        Here I want to add the increment logic, something like this 
        $counter = $counter+ 1  -->
   <xsl:value-of select="."/>
  </xsl:if>
 </xsl:for-each>
</xsl:template>

<xsl:template match="some_pattern">
 <Attribute>
  <!-- the final 'counter' value from above xsl block needs to be outputted here -->
  <xsl:value-of select="$counter"/>
 </Attribute>
</xsl:template>
4

0 に答える 0