title: Add parent element and rename the child element
body: <p>I am trying to loop child elements under import and export. Create a parent element fields and put all the elements which the name is field into it, just under import, not include the elements field under structure, Create element structures over all elements structure, and the last work is rename all the element with the value of attribute name. I just know copy all of them first and can not go to next step to create the right template.</p>
  
  <p>input:</p>
  
  <pre><code>&lt;?xml version='1.0'?&gt;
  &lt;jco name="TEST" timestamp="1275691115508" version="1.0"&gt;
  &lt;import&gt;
      &lt;field name="RESERVED_IN"&gt;12345&lt;/field&gt;
      &lt;structure name="GM_HEADER"&gt;
                  &lt;field name="PSTNG_DATE"&gt;2004-07-02&lt;/field&gt;
          &lt;field name="DOC_DATE"&gt;2004-04-02&lt;/field&gt;
      &lt;/structure&gt;
      &lt;structure name="TESTRUN"&gt;
          &lt;field name="TESTRUN"&gt;&lt;/field&gt;
      &lt;/structure&gt;
  &lt;/import&gt;
  &lt;export&gt;
      &lt;field name="RESERVED_OUT"&gt;&lt;/field&gt;
      &lt;structure name="GM_HEADER_RET"&gt;
          &lt;field name="MAT_DOC"&gt;&lt;/field&gt;
          &lt;field name="DOC_YEAR"&gt;0000&lt;/field&gt;
      &lt;/structure&gt;
  &lt;/export&gt;
  &lt;/jco&gt;
  </code></pre>
  
  <p>desired output:</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;jco version="1.0" name="TEST"&gt;
      &lt;import&gt;
          &lt;fields&gt;
              &lt;RESERVED_IN&gt;12345&lt;/RESERVED_IN&gt;
          &lt;/fields&gt;
          &lt;structures&gt;
              &lt;GM_HEADER&gt;
                  &lt;PSTNG_DATE&gt;2004-07-02&lt;/PSTNG_DATE&gt;
                  &lt;DOC_DATE&gt;2004-04-02&lt;/DOC_DATE&gt;
              &lt;/GM_HEADER&gt;
              &lt;TESTRUN&gt;
                  &lt;TESTRUN&gt;&lt;/TESTRUN&gt;
              &lt;/TESTRUN&gt;
          &lt;/structures&gt;
     &lt;/import&gt;
     &lt;export&gt;
         &lt;fields&gt;
             &lt;RESERVED_OUT&gt;&lt;/RESERVED_OUT&gt;
         &lt;/fields&gt;
         &lt;structures&gt;
             &lt;GM_HEADER_RET&gt;
                 &lt;MAT_DOC&gt;&lt;/MAT_DOC&gt;
                 &lt;DOC_YEAR&gt;0000&lt;/DOC_YEAR&gt;
             &lt;/GM_HEADER_RET&gt;
         &lt;/structures&gt;
     &lt;/export&gt;
  &lt;/jco&gt;
  </code></pre>
  
  <p>Below is my xslt, but it seems messed up.</p>
  
  <pre><code>    &lt;xsl:template match="node()|@*"&gt;
              &lt;xsl:copy&gt;
                  &lt;xsl:apply-templates select="node()|@*" /&gt;
              &lt;/xsl:copy&gt;
          &lt;/xsl:template&gt;
  
          &lt;xsl:template match="import"&gt;
              &lt;fields&gt;
                  &lt;xsl:for-each select="/field"&gt;
                      &lt;xsl:call-template name="field" /&gt;
                  &lt;/xsl:for-each&gt;
              &lt;/fields&gt;
              &lt;structures&gt;
                  &lt;xsl:for-each select="/structure"&gt;
                      &lt;xsl:element name="{@name}"&gt;
                          &lt;xsl:value-of select="." /&gt;
                      &lt;/xsl:element&gt;
                      &lt;xsl:call-template name="field" /&gt;
                  &lt;/xsl:for-each&gt;
              &lt;/structures&gt;
          &lt;/xsl:template&gt;
  
          &lt;xsl:template name="field"&gt;
              &lt;xsl:for-each select="/field"&gt;
                      &lt;xsl:element name="{@name}"&gt;
                          &lt;xsl:value-of select="." /&gt;
                      &lt;/xsl:element&gt;
                  &lt;/xsl:for-each&gt;
          &lt;/xsl:template&gt;
  </code></pre>