title: XSLT copy over the node structure of parent within foreach
body: <p>I have an input XML which needs to be transformed to output format given below.
  The problem i am facing is copying the exact tag "IssuedList" to the output.As I have a for each loop its not allowing to apply identical transform.Is there any other method to achieve the same result.Given below is my XSLT which i tried out</p>
  
  <p>Input XML:</p>
  
  <pre><code>     &lt;Books&gt;
      &lt;Book&gt;
      &lt;Id&gt;1&lt;/Id&gt;
      &lt;Name&gt;ABC&lt;/Name&gt;
      &lt;Categories RefId="1"&gt;
        &lt;Priority&gt;High&lt;/Priority&gt;
      &lt;/Category&gt;
      &lt;/Categories&gt;
      &lt;Categories RefId="2"&gt;
       &lt;Category&gt;
        &lt;Priority&gt;Low&lt;/Priority&gt;
       &lt;Category&gt;
      &lt;/Categories&gt;
      &lt;IssuedList&gt;
      &lt;IssueList&gt;
       &lt;Number&gt;1&lt;/Number&gt;
       &lt;Name&gt;ABC&lt;/Name&gt;
       &lt;/IssueList&gt;
       &lt;IssueList&gt;
       &lt;Number&gt;1&lt;/Number&gt;
       &lt;Name&gt;ABC&lt;/Name&gt;
       &lt;/IssueList&gt;
      &lt;/IssuedList&gt;
      &lt;/Book&gt;
      &lt;Book&gt;
      &lt;Id&gt;2&lt;/Id&gt;
      &lt;Name&gt;DEF&lt;/Name&gt;
      &lt;Categories RefId="1"&gt;
       &lt;Category&gt;
        &lt;Priority&gt;High&lt;/Priority&gt;
      &lt;/Category&gt;
     &lt;/Categories&gt;
      &lt;Categories RefId="2"&gt;
      &lt;Category&gt;
        &lt;Priority&gt;Low&lt;/Priority&gt;
      &lt;/Category&gt;
      &lt;/Categories&gt;
      &lt;IssuedList&gt;
      &lt;IssueList&gt;
       &lt;Number&gt;1&lt;/Number&gt;
       &lt;Name&gt;DEF&lt;/Name&gt;
       &lt;/IssueList&gt;
      &lt;/IssuedList&gt;
      &lt;/Book&gt;   
  </code></pre>
  
  <p>And would like to see the transformed output as </p>
  
  <pre><code> &lt;Books&gt;
      &lt;Book&gt;
      &lt;Id&gt;1&lt;/Id&gt;
      &lt;Name&gt;ABC&lt;/Name&gt;
      &lt;RefId&gt;1&lt;/RefId&gt;
      &lt;Priority&gt;High&lt;/Priority&gt;
      &lt;IssuedList&gt;
       &lt;IssueList&gt;
       &lt;Number&gt;1&lt;/Number&gt;
       &lt;Name&gt;ABC&lt;/Name&gt;
       &lt;/IssueList&gt;
       &lt;IssueList&gt;
       &lt;Number&gt;1&lt;/Number&gt;
       &lt;Name&gt;ABC&lt;/Name&gt;
       &lt;/IssueList&gt;
      &lt;/IssuedList&gt;
      &lt;/Book&gt;
      &lt;Book&gt;
      &lt;Id&gt;1&lt;/Id&gt;
      &lt;Name&gt;ABC&lt;/Name&gt;
      &lt;RefId&gt;2&lt;/RefId&gt;
      &lt;Priority&gt;Low&lt;/Priority&gt;
      &lt;IssuedList&gt;
       &lt;IssueList&gt;
       &lt;Number&gt;1&lt;/Number&gt;
       &lt;Name&gt;ABC&lt;/Name&gt;
       &lt;/IssueList&gt;
       &lt;IssueList&gt;
       &lt;Number&gt;1&lt;/Number&gt;
       &lt;Name&gt;ABC&lt;/Name&gt;
       &lt;/IssueList&gt;
      &lt;/IssuedList&gt;
      &lt;/Book&gt;
      &lt;Book&gt;
      &lt;Id&gt;2&lt;/Id&gt;
      &lt;Name&gt;DEF&lt;/Name&gt;
      &lt;RefId&gt;1&lt;/RefId&gt;
      &lt;Priority&gt;High&lt;/Priority&gt;
      &lt;IssuedList&gt;
      &lt;IssueList&gt;
       &lt;Number&gt;1&lt;/Number&gt;
       &lt;Name&gt;DEF&lt;/Name&gt;
       &lt;/IssueList&gt;
      &lt;/IssuedList&gt;
      &lt;/Book&gt;
      &lt;Book&gt;
      &lt;Id&gt;2&lt;/Id&gt;
      &lt;Name&gt;DEF&lt;/Name&gt;
      &lt;RefId&gt;2&lt;/RefId&gt;
      &lt;Priority&gt;Low&lt;/Priority&gt;
      &lt;IssuedList&gt;
      &lt;IssueList&gt;
       &lt;Number&gt;1&lt;/Number&gt;
       &lt;Name&gt;DEF&lt;/Name&gt;
       &lt;/IssueList&gt;
      &lt;/IssuedList&gt;
      &lt;/Book&gt;
      &lt;/Books&gt;
  </code></pre>
  
  <p>I have written the XSLT as below</p>
  
  <pre><code>&lt;xsl:for-each select ="/Books/Book"&gt;
     &lt;xsl:variable name="Id" select ="Id"&gt;&lt;/xsl:variable&gt;
     &lt;xsl:variable name="Name" select ="Name"&gt;&lt;/xsl:variable&gt;
     &lt;xsl:for-each select ="Categories/Category"&gt;
              &lt;Book&gt;                          
                  &lt;RefId&gt;
                    &lt;xsl:value-of select ="@RefId"&gt;&lt;/xsl:value-of&gt;
                  &lt;/RefId&gt;
                   &lt;Id&gt;
                    &lt;xsl:value-of select ="$Id"&gt;&lt;/xsl:value-of&gt;
                  &lt;/Id&gt;
                  &lt;Name&gt;
                    &lt;xsl:value-of select ="$Name"&gt;&lt;/xsl:value-of&gt;
                  &lt;/Name&gt;
   &lt;/Book&gt;
  &lt;/xsl:for-each&gt;
  &lt;/xsl:for-each&gt;
  </code></pre>