XSL - replace all instances of a tag with another recursively
<p>I have an XML looking like this:</p>

<pre><code>&lt;Viewbox Width="29.513" Height="57.478"
  &gt;
  &lt;Canvas&gt;
    &lt;Canvas&gt;
    &lt;!-- Layer 1/&lt;Group&gt;/&lt;Group&gt;/&lt;Compound Path&gt; --&gt;
    &lt;Path Fill="#ffffffff" Data="F1... Z"/&gt;
    &lt;Path StrokeThickness="0.9" Stroke="#ff59595b" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeLineJoin="Round" Data="F1 ...698"/&gt;
  &lt;/Canvas&gt;
  &lt;/Canvas&gt;


&lt;/Viewbox&gt;
</code></pre>

<p>My XSL looks like this:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;
  &lt;xsl:output method="xml" indent="yes"/&gt;
  &lt;xsl:template match="/" &gt;
    &lt;DrawImage&gt;
      &lt;xsl:for-each select="//Canvas"&gt;
        &lt;DrawingGroup&gt;&lt;xsl:copy-of select="child::*" /&gt;&lt;/DrawingGroup&gt;
    &lt;/xsl:for-each&gt;   
      &lt;xsl:for-each select="//Path"&gt;
      &lt;GeometryDrawing&gt;
 &lt;xsl:choose&gt;
    &lt;xsl:when test="@Fill"&gt;        
        &lt;xsl:attribute name="Brush"&gt;
          &lt;xsl:value-of select="@Fill"/&gt;
        &lt;/xsl:attribute&gt;
       &lt;/xsl:when&gt;
    &lt;xsl:when test="@Stroke"&gt;        
        &lt;xsl:attribute name="Brush"&gt;
          &lt;xsl:value-of select="@Stroke"/&gt;
        &lt;/xsl:attribute&gt;
       &lt;/xsl:when&gt;
   &lt;/xsl:choose&gt;
        &lt;xsl:attribute name="Geometry"&gt;
          &lt;xsl:value-of select="@Data"/&gt;
        &lt;/xsl:attribute&gt;
         &lt;xsl:choose&gt;
    &lt;xsl:when test="not(string-length(@StrokeThickness)&amp;lt;1 or string-length(@StrokeStartLineCap)&amp;lt;1  or string-length(@StrokeEndLineCap)&amp;lt;1  or string-length(@StrokeLineJoin)&amp;lt;1)"&gt;    
        &lt;Pen&gt;
 &lt;xsl:choose&gt;
    &lt;xsl:when test="@StrokeThickness"&gt;           
          &lt;xsl:attribute name="Thickness"&gt;
            &lt;xsl:value-of select="@StrokeThickness"/&gt;
          &lt;/xsl:attribute&gt;
       &lt;/xsl:when&gt;
   &lt;/xsl:choose&gt;      
 &lt;xsl:choose&gt;
    &lt;xsl:when test="@StrokeStartLineCap"&gt;  
      &lt;xsl:attribute name="StartLineCap"&gt;
            &lt;xsl:value-of select="@StrokeStartLineCap"/&gt;
          &lt;/xsl:attribute&gt;
                 &lt;/xsl:when&gt;
   &lt;/xsl:choose&gt;
    &lt;xsl:choose&gt;
    &lt;xsl:when test="@StrokeEndLineCap"&gt;  
      &lt;xsl:attribute name="EndLineCap"&gt;
            &lt;xsl:value-of select="@StrokeEndLineCap"/&gt;
          &lt;/xsl:attribute&gt;
               &lt;/xsl:when&gt;
   &lt;/xsl:choose&gt;
         &lt;xsl:choose&gt;
    &lt;xsl:when test="@StrokeLineJoin"&gt;  
      &lt;xsl:attribute name="LineJoin"&gt;
            &lt;xsl:value-of select="@StrokeLineJoin"/&gt;
          &lt;/xsl:attribute&gt;
               &lt;/xsl:when&gt;
   &lt;/xsl:choose&gt;
        &lt;/Pen&gt;
       &lt;/xsl:when&gt;
   &lt;/xsl:choose&gt;      
      &lt;/GeometryDrawing&gt;
      &lt;/xsl:for-each&gt;
    &lt;/DrawImage&gt;
  &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</code></pre>

<p>Something isn't right. My output was <em>supposed</em> to look like shown below, but instead I get the Geometrydrawings outside DrawingGroup and DrawingGroup is not nested like Canvas was.</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;DrawImage&gt;
  &lt;DrawingGroup&gt;
  &lt;DrawingGroup&gt;
  &lt;GeometryDrawing Brush="#ffffffff" Geometry="F1....478 Z" /&gt;
  &lt;GeometryDrawing Brush="#ff59595b" Geometry="F1...98"&gt;
    &lt;Pen Thickness="0.9" StartLineCap="Round" EndLineCap="Round" LineJoin="Round" /&gt;
  &lt;/GeometryDrawing&gt;
  &lt;/DrawingGroup&gt;
  &lt;/DrawingGroup&gt;
&lt;/DrawImage&gt;
</code></pre>

<p>I hope someone can tell me what to put inside my DrawingGroup element in my xsl</p>