title: XSLT: Copy attribute into a new element in the child
body: <p>I want to copy the id attribute on a specific element (parent in this case) into a new element within the child of parent. </p>
  
  <p>My XML is as follows:</p>
  
  <pre><code>&lt;wrapper&gt;
      &lt;parent id="1"&gt;
           &lt;child&gt;
              content
           &lt;/child&gt;
      &lt;/parent&gt;
  &lt;/wrapper&gt;
  </code></pre>
  
  <p>I need the output to be like this:</p>
  
  <pre><code>&lt;wrapper&gt;
      &lt;parent&gt;
          &lt;child&gt;
              &lt;parentid&gt;1&lt;/parentid&gt; 
              content
          &lt;/child&gt;
      &lt;/parent&gt;
  &lt;/wrapper&gt;
  </code></pre>
  
  <p>From the examples below this one does what i want, except that it puts the new element in parent, whilst i want in the child:</p>
  
  <pre><code>&lt;xsl:template match="parent[@id]"&gt;
      &lt;parent&gt;
          &lt;xsl:apply-templates select="@*[name() != 'id']" /&gt;
              &lt;parentid&gt;
                  &lt;xsl:value-of select="@id" /&gt;
              &lt;/parentid&gt;
          &lt;xsl:apply-templates select="node()"/&gt;
      &lt;/parent&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>I've been messing around with the above but i still can't get it the way i want. Thanks in advance.</p>