user3237163
user3237163

Reputation: 1

Initializing Variables inside a loop in XSL and use it next for-each loop

I want to initialize a variable inside one for-each block to capture the value stored in the last iteration and use it in the next for-each block with the last value.

<xsl:for-each select="tns:ClientContributionDetails">
        <ns1:Line>
          <ns1:LineNumber>
            <xsl:value-of select="position()*2+1"/>
          </ns1:LineNumber>
        </ns1:Line> 
        <ns1:Line>
          <ns1:LineNumber>
            <xsl:value-of select="(position()+1)*2"/>
          </ns1:LineNumber>
       </ns1:Line>  

</xsl:for-each>
<xsl:for-each select="tns:ThirdPartyContributionDetails">
  <ns1:Line>
          <ns1:LineNumber>
            <!--I want here the loop begins with the value stored in the last iteration    of the pervious for-each--> 
          </ns1:LineNumber>

 </xsl:for-each>

Upvotes: 0

Views: 659

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117043

initialize a variable inside one for-each block to capture the value stored in the last iteration

The answer becomes trivial once you change the question:

<xsl:variable name="lastLine" select="2*count(tns:ClientContributionDetails) + 2" />

You initialize this after the first for-each block, not inside it.

Upvotes: 1

Related Questions