title: Renaming nodes and values with xslt
body: <p>I'm new to xslt, and have a task that I'm not really sure where to go with. I want to rename nodes, but maintain the format all node declarations. In the actual context I'll be applying this to, I'll be doing a series of renames like this, but for the sake of brevity, the sample I've written up only involves renaming one node. I am using XSL 1.0.</p>
  
  <p><strong>Input:</strong></p>
  
  <pre><code>&lt;variables&gt;
    &lt;var&gt;
      &lt;RENAME&gt; a &lt;/RENAME&gt;
    &lt;/var&gt;
    &lt;var RENAME='b'/&gt;
    &lt;var&gt;
      &lt;DO_NOT_TOUCH&gt; c &lt;/DO_NOT_TOUCH&gt;
    &lt;/var&gt;
    &lt;var DO_NOT_TOUCH='d'/&gt;
  &lt;/variables&gt;
  </code></pre>
  
  <p><strong>Desired Output:</strong></p>
  
  <pre><code>&lt;variables&gt;
    &lt;var&gt;
      &lt;DONE&gt; a &lt;/DONE&gt;
    &lt;/var&gt;
    &lt;var DONE='b'/&gt;
    &lt;var&gt;
      &lt;DO_NOT_TOUCH&gt; c &lt;/DO_NOT_TOUCH&gt;
    &lt;/var&gt;
    &lt;var DO_NOT_TOUCH='d'/&gt;
  &lt;/variables&gt;
  </code></pre>
  
  <p><strong>My xslt:</strong></p>
  
  <pre><code>&lt;xsl:template match="RENAME"&gt;
          &lt;RENAMED&gt;
                  &lt;xsl:apply-templates select="@*|node()"/&gt;
          &lt;/RENAMED&gt;
  &lt;/xsl:template&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;
  </code></pre>
  
  <p><strong>Current Output</strong></p>
  
  <pre><code>&lt;variables&gt;
    &lt;var&gt;
      &lt;RENAMED&gt; a &lt;/RENAMED&gt;
    &lt;/var&gt;
    &lt;var RENAME="b"&gt;
    &lt;/var&gt;
    &lt;var&gt;
      &lt;DO_NOT_TOUCH&gt; c &lt;/DO_NOT_TOUCH&gt;
    &lt;/var&gt;
    &lt;var DO_NOT_TOUCH="d"&gt;
    &lt;/var&gt;
  &lt;/variables&gt;
  </code></pre>