title: Copying a complete XML Element using XSLT
body: <p>I am translating one XML file to another.  I want to copy a single, complete element from the original xml into the new xml.  I have tried using the identity transformation but can only get that to work if I copy the entire document.  If I try to limit to just a single element (which contains a lot of data), I get the values of everything in the document - not the xml tags and not just what is in the desired element.  I'm relatively new to XSLT so I'm probably not understanding the identity transformation process correctly.</p>
  
  <p>Here is my sample input:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;DataExtract Version="1.0"&gt;
      &lt;ImportExport&gt;Export&lt;/ImportExport&gt;
      &lt;Entities&gt;
          &lt;Entity&gt;
              &lt;Data&gt;UnwantedDataA&lt;/Data&gt;
              &lt;Data&gt;UnwantedDataB&lt;/Data&gt;
          &lt;/Entity&gt;
          &lt;Entity&gt;
              &lt;Data&gt;UnwantedDataC&lt;/Data&gt;
              &lt;Data&gt;UnwantedDataD&lt;/Data&gt;
          &lt;/Entity&gt;
          &lt;Entity&gt;
              &lt;EntityData&gt;
                  &lt;Data&gt;ABC&lt;/Data&gt;
                  &lt;Data&gt;DEF&lt;/Data&gt;
                  &lt;Data&gt;GHI&lt;/Data&gt;
                  &lt;SpecialData id="1"&gt;Definitely wanted&lt;/SpecialData&gt;
              &lt;/EntityData&gt;
          &lt;/Entity&gt;
      &lt;/Entities&gt;
  &lt;/DataExtract&gt;
  </code></pre>
  
  <p>I want to get the EntityData element and put it out exactly as it is in the input.  </p>
  
  <p>If I use the following to copy the entire input document, I get a full duplicate with xml tags, etc.</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
      &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:stylesheet&gt;
  </code></pre>
  
  <p>But if I try to only get the EntityData element using the following code:</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
      &lt;xsl:template match="EntityData"&gt;
          &lt;xsl:copy&gt;
              &lt;xsl:apply-templates select="@*|node()"/&gt;
          &lt;/xsl:copy&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>I get the values instead of the xml and for the entire document, not just EntityData:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
      Export
  
  
              UnwantedDataA
              UnwantedDataB
  
  
              UnwantedDataC
              UnwantedDataD
  
  
              &lt;EntityData&gt;
                  ABC
                  DEF
                  GHI
                  Definitely wanted
              &lt;/EntityData&gt;
  </code></pre>
  
  <p>I really want:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;EntityData&gt;
      &lt;Data&gt;ABC&lt;/Data&gt;
      &lt;Data&gt;DEF&lt;/Data&gt;
      &lt;Data&gt;GHI&lt;/Data&gt;
      &lt;SpecialData id="1"&gt;Definitely wanted&lt;/SpecialData&gt;
  &lt;/EntityData&gt;
  </code></pre>
  
  <p>I've tried different options with copy and copy-of and everything I have read talks about copying the entire document and possibly excluding a few things. I want to exclude everything except the EntityData element.</p>