title: Transform XML with multiple output using XSLT into XML with single output
body: <p>I'm trying to transform (flatten) XML with multiple output using XSLT into XML with single output. But  node which must be duplicated for each  node is ignored. XML file has two outputs: HEAD and EXPERIMENT. </p>
  
  <p>Source XML document:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ELEMENT&gt;
      &lt;HEAD&gt;
          &lt;FIRSTNAME&gt;Anton&lt;/FIRSTNAME&gt;
          &lt;SURNAME&gt;Konchik&lt;/SURNAME&gt;
          &lt;REPORTDATE&gt;01.01.2019&lt;/REPORTDATE&gt;
      &lt;/HEAD&gt;
      &lt;EXPERIMENT&gt;
          &lt;NAME&gt;EXPERIMENT1&lt;/NAME&gt;
          &lt;DATE&gt;01.01.2018&lt;/DATE&gt;
          &lt;RESULT&gt;POSITIVE&lt;/RESULT&gt;
      &lt;/EXPERIMENT&gt;
      &lt;EXPERIMENT&gt;
          &lt;NAME&gt;EXPERIMENT2&lt;/NAME&gt;
          &lt;DATE&gt;01.01.2019&lt;/DATE&gt;
          &lt;RESULT&gt;NEGATIVE&lt;/RESULT&gt;
      &lt;/EXPERIMENT&gt;
      &lt;EXPERIMENT&gt;
          &lt;NAME&gt;EXPERIMENT3&lt;/NAME&gt;
          &lt;DATE&gt;01.01.2017&lt;/DATE&gt;
          &lt;RESULT&gt;NOTSURE&lt;/RESULT&gt;
      &lt;/EXPERIMENT&gt;
  &lt;/ELEMENT&gt;
  </code></pre>
  
  <p>By using code below I want to duplicate HEAD node inside each EXPERIMENT node.
  XSLT transformation code:</p>
  
  <pre><code>&lt;?xml version='1.0' ?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:output method="xml" indent="yes" version="2.0" encoding="UTF-8" /&gt;
      &lt;xsl:template match="/"&gt;
          &lt;xsl:element name="ELEMENT"&gt;
              &lt;xsl:for-each select="ELEMENT/EXPERIMENT"&gt;
                  &lt;xsl:element name="EXPERIMENT"&gt;
  
                      &lt;xsl:element name="NAME"&gt;
                            &lt;xsl:value-of select="./NAME"/&gt;
                      &lt;/xsl:element&gt;
  
                      &lt;xsl:element name="DATE"&gt;
                            &lt;xsl:value-of select="./DATE"/&gt;
                      &lt;/xsl:element&gt;
  
                      &lt;xsl:element name="RESULT"&gt;
                            &lt;xsl:value-of select="./RESULT"/&gt;
                      &lt;/xsl:element&gt;
  
                          &lt;xsl:for-each select="ELEMENT/HEAD"&gt;
                             &lt;xsl:element name="FIRSTNAME"&gt;
                                    &lt;xsl:value-of select="./FIRSTNAME"/&gt;
                              &lt;/xsl:element&gt;
                             &lt;xsl:element name="SURNAME"&gt;
                                    &lt;xsl:value-of select="./SURNAME"/&gt;
                              &lt;/xsl:element&gt;
                             &lt;xsl:element name="REPORTDATE"&gt;
                                    &lt;xsl:value-of select="./REPORTDATE"/&gt;
                              &lt;/xsl:element&gt;
                          &lt;/xsl:for-each&gt;
  
                  &lt;/xsl:element&gt;          
              &lt;/xsl:for-each&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Excepted result:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ELEMENT&gt;
      &lt;EXPERIMENT&gt;
          &lt;NAME&gt;EXPERIMENT1&lt;/NAME&gt;
          &lt;DATE&gt;01.01.2018&lt;/DATE&gt;
          &lt;RESULT&gt;POSITIVE&lt;/RESULT&gt;
          &lt;FIRSTNAME&gt;Anton&lt;/FIRSTNAME&gt;
          &lt;SURNAME&gt;Konchik&lt;/SURNAME&gt;
          &lt;REPORTDATE&gt;01.01.2019&lt;/REPORTDATE&gt;
      &lt;/EXPERIMENT&gt;
      &lt;EXPERIMENT&gt;
          &lt;NAME&gt;EXPERIMENT2&lt;/NAME&gt;
          &lt;DATE&gt;01.01.2019&lt;/DATE&gt;
          &lt;RESULT&gt;NEGATIVE&lt;/RESULT&gt;
          &lt;FIRSTNAME&gt;Anton&lt;/FIRSTNAME&gt;
          &lt;SURNAME&gt;Konchik&lt;/SURNAME&gt;
          &lt;REPORTDATE&gt;01.01.2019&lt;/REPORTDATE&gt;
      &lt;/EXPERIMENT&gt;
      &lt;EXPERIMENT&gt;
          &lt;NAME&gt;EXPERIMENT3&lt;/NAME&gt;
          &lt;DATE&gt;01.01.2017&lt;/DATE&gt;
          &lt;RESULT&gt;NOTSURE&lt;/RESULT&gt;
          &lt;FIRSTNAME&gt;Anton&lt;/FIRSTNAME&gt;
          &lt;SURNAME&gt;Konchik&lt;/SURNAME&gt;
          &lt;REPORTDATE&gt;01.01.2019&lt;/REPORTDATE&gt;
      &lt;/EXPERIMENT&gt;
  &lt;/ELEMENT&gt;
  </code></pre>
  
  <p>But HEAD node is ignored.
  Actual result:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ELEMENT&gt;
    &lt;EXPERIMENT&gt;
      &lt;NAME&gt;EXPERIMENT1&lt;/NAME&gt;
      &lt;DATE&gt;01.01.2018&lt;/DATE&gt;
      &lt;RESULT&gt;POSITIVE&lt;/RESULT&gt;
    &lt;/EXPERIMENT&gt;
    &lt;EXPERIMENT&gt;
      &lt;NAME&gt;EXPERIMENT2&lt;/NAME&gt;
      &lt;DATE&gt;01.01.2019&lt;/DATE&gt;
      &lt;RESULT&gt;NEGATIVE&lt;/RESULT&gt;
    &lt;/EXPERIMENT&gt;
    &lt;EXPERIMENT&gt;
      &lt;NAME&gt;EXPERIMENT3&lt;/NAME&gt;
      &lt;DATE&gt;01.01.2017&lt;/DATE&gt;
      &lt;RESULT&gt;NOTSURE&lt;/RESULT&gt;
    &lt;/EXPERIMENT&gt;
  &lt;/ELEMENT&gt;
  </code></pre>
  
  <p>Thanks for your help.</p>