title: how to copy the data of variable of one foreach to another for each in xslt
body: <p>XML</p>
  
  <pre><code>&lt;swift&gt;
   &lt;message&gt;
       &lt;block2 type="input"&gt;
          &lt;messageType&gt;102&lt;/messageType&gt;
          &lt;receiverAddress&gt;BKTRUS33XBRD&lt;/receiverAddress&gt;
          &lt;messagePriority&gt;N&lt;/messagePriority&gt;     
       &lt;/block2&gt;
       &lt;block3&gt;
       &lt;tag&gt;
       &lt;name&gt;32&lt;/name&gt;
       &lt;value&gt;praveen&lt;/value&gt;
       &lt;/tag&gt;
       &lt;tag&gt;
       &lt;name&gt;42&lt;/name&gt;
       &lt;value&gt;pubby&lt;/value&gt;
       &lt;/tag&gt;
       &lt;/block3&gt; 
       &lt;block4&gt;
       &lt;tag&gt;
       &lt;name&gt;77&lt;/name&gt;
       &lt;value&gt;pravz&lt;/value&gt;
       &lt;/tag&gt;
       &lt;tag&gt;
       &lt;name&gt;77&lt;/name&gt;
       &lt;value&gt;pubbypravz&lt;/value&gt;
       &lt;/tag&gt;
       &lt;tag&gt;
       &lt;name&gt;99&lt;/name&gt;
       &lt;value&gt;USA&lt;/value&gt;
       &lt;/tag&gt;
       &lt;tag&gt;
       &lt;name&gt;99&lt;/name&gt;
       &lt;value&gt;UK&lt;/value&gt;
       &lt;/tag&gt;
       &lt;tag&gt;
       &lt;name&gt;76&lt;/name&gt;
       &lt;value&gt;shanmu&lt;/value&gt;
       &lt;/tag&gt;
    &lt;/block4&gt;
   &lt;/message&gt;
  &lt;/swift&gt;
  </code></pre>
  
  <p>XSL</p>
  
  <pre><code>      &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  
            &lt;xsl:output method="text" /&gt;
             &lt;xsl:param name="count" select="000001"&gt;&lt;/xsl:param &gt;
              &lt;xsl:template match="/"&gt;
               &lt;xsl:for-each select ="swift/message"&gt;
  
               &lt;xsl:variable name="newtype"&gt;
          &lt;xsl:choose&gt;
          &lt;xsl:when test="block2[@type = 'input']"&gt;
  
       &lt;xsl:value-of  select=" concat('O', block2/messageType,block2/messagePriority )"/&gt;,&lt;xsl:text/&gt;
              &lt;/xsl:when&gt;
  
              &lt;xsl:when test="block2[@type = 'output']"&gt;
       &lt;xsl:value-of  select=" concat('I', block2/messageType,block2/messagePriority )"/&gt;,&lt;xsl:text/&gt;
          &lt;/xsl:when&gt;
             &lt;/xsl:choose&gt;
              &lt;/xsl:variable&gt;
  
      &lt;xsl:for-each select ="/swift/message/block3/tag[name='32']"&gt;
      &lt;xsl:variable name = "first-val" select="value"/&gt;
  
      &lt;xsl:for-each select ="/swift/message/block4/tag[name='77']"&gt;
      &lt;xsl:value-of select="concat($count,',',$first-val, ',',value)"/&gt;
  
      &lt;xsl:text&gt;
          &lt;/xsl:text&gt;
           &lt;/xsl:for-each&gt;
         &lt;/xsl:for-each&gt;
      &lt;/xsl:for-each&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>i need to copy the data of which were i have declared name of "<strong>newtype</strong>" required the data should print in place of this bellow line </p>
  
  <pre><code>  &lt;xsl:value-of select="concat($newtype,',',$first-val, ',',value)"/&gt;
  </code></pre>
  
  <p>but above which was showing wrong because variable name was declared out of the scope so can any modify make me to reach that ouput please </p>
  
  <p>the above i have hot coded this value 000001 but needed increment for every record </p>
  
  <p>Expected Output</p>
  
  <p><strong>O102N,000001,praveen,pravz,USA</strong></p>
  
  <p><strong>O102N,000002, praveen,pubbypravz,UK</strong></p>