0

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>
2
  • My expected result should be in the format:- for ClientContributionDetails in the first for-each block if the last value of the second tag of <ns1:LineNumber> results in 5 then in the next loop for tns:ThirdPartyContributionDetails i want my line number to start with 6 so dat after i can manipulate it using position() again to suite up my needs Commented Jan 26, 2014 at 9:33
  • 2
    Not possible. XSLT does not work this way. You have to change your approach. Include the (relevant snippet of) input XML and the desired output for that. Also fix your XSLT snippet, it's badly indented and syntactically invalid. Commented Jan 26, 2014 at 9:40

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@user3237163: If this answer solves your problem, please accept it (mark the tick on the left).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.