title: Using copy-of with document() to add SVGs to XHTML output
body: <p>While processing my XML, I'm trying to copy an SVG file referenced from an <code>href</code> attribute directly into my output HTML with the following line:</p>
  
  <pre><code> &lt;xsl:copy-of copy-namespaces="yes" select="document(@href)"/&gt;
  </code></pre>
  
  <p>The <code>copy-namespaces</code> should not be necessary since the default value is "yes" anyway, but I've added it to prevent questions about whether or not I've tried it.</p>
  
  <p>The files are copied into the HTML, but any namespaced elements are hosed. For example, a file that looks like this before being copied:</p>
  
  <pre><code>  &lt;rdf:RDF&gt;
        &lt;cc:Work rdf:about=""&gt;
          &lt;dc:format&gt;image/svg+xml&lt;/dc:format&gt;
          &lt;dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/&gt;
          &lt;dc:title/&gt;
        &lt;/cc:Work&gt;
      &lt;/rdf:RDF&gt;
    &lt;/metadata&gt;
    &lt;g transform="translate(-519.21143,-667.79077)" id="layer1"&gt;
      &lt;image xlink:href="data:image/png;base64
  </code></pre>
  
  <p>Looks like this afterwards: </p>
  
  <pre><code>  &lt;_0:RDF xmlns:_0="http://www.w3.org/1999/02/22-rdf-syntax-ns#"&gt;
        &lt;_0:Work xmlns:_0="http://creativecommons.org/ns#" about=""&gt;
          &lt;_0:format xmlns:_0="http://purl.org/dc/elements/1.1/"&gt;image/svg+xml&lt;/_0:format&gt;
          &lt;_0:type xmlns:_0="http://purl.org/dc/elements/1.1/" resource="http://purl.org/dc/dcmitype/StillImage"/&gt;
          &lt;_0:title xmlns:_0="http://purl.org/dc/elements/1.1/"/&gt;
        &lt;/_0:Work&gt;
      &lt;/_0:RDF&gt;
    &lt;/metadata&gt;
    &lt;g id="layer1" transform="translate(-519.21143,-667.79077)"&gt;
      &lt;image href="data:image/png;base64
  </code></pre>
  
  <p>The missing xlink namespace on the <code>href</code> value of the image element is particularly problematic.</p>
  
  <p>Any thoughts on how I can do this differently to read in the SVG file without any interpretation?</p>
  
  <p>I've found one solution that "works", but it's a hack and I'd like something more elegant:</p>
  
  <pre><code>&lt;xsl:template name="topic-image-svg"&gt;
      &lt;!-- Generate tags to embed SWFs --&gt;
      &lt;xsl:element name="div"&gt;
        &lt;xsl:if test="@width"&gt;
          &lt;xsl:attribute name="width"&gt;
            &lt;xsl:value-of select="@width"/&gt;
          &lt;/xsl:attribute&gt;
        &lt;/xsl:if&gt;
        &lt;xsl:if test="@height"&gt;
          &lt;xsl:attribute name="height"&gt;
            &lt;xsl:value-of select="@height"/&gt;
          &lt;/xsl:attribute&gt;
        &lt;/xsl:if&gt;     
          &lt;xsl:apply-templates select="document(@href)" mode="svg"/&gt;
      &lt;/xsl:element&gt;
    &lt;/xsl:template&gt;
  
    &lt;xsl:template match="*" mode="svg"&gt;
      &lt;xsl:copy copy-namespaces="yes"&gt;
        &lt;xsl:for-each select="@*"&gt;
          &lt;xsl:choose&gt;
            &lt;xsl:when test="self::node()[name() = 'xlink:href']"&gt;
              &lt;xsl:attribute name="xlink:href"&gt;&lt;xsl:value-of select="."&gt;&lt;/xsl:value-of&gt;&lt;/xsl:attribute&gt;
            &lt;/xsl:when&gt;
            &lt;xsl:otherwise&gt;
              &lt;xsl:copy&gt;&lt;/xsl:copy&gt;
            &lt;/xsl:otherwise&gt;
          &lt;/xsl:choose&gt;
        &lt;/xsl:for-each&gt;
       &lt;xsl:apply-templates mode="svg"&gt;&lt;/xsl:apply-templates&gt;
      &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
  </code></pre>