title: XSLT -Cut and Paste
body: <p>how to do cut and paste in xslt? suppose my xml like this,</p>
  
  <pre><code>  &lt;root&gt;
      &lt;header&gt;
        some nodes
      &lt;/header&gt;
      &lt;body&gt;
      &lt;p&gt;
        some text
      &lt;link&gt;1&lt;/link&gt;
        &lt;note xml:id="c5-note-0001" numbered="no"&gt;text&lt;/note&gt;
      &lt;/p&gt;
      &lt;p&gt;
        some text
        &lt;link&gt;2&lt;/link&gt;
        &lt;figure&gt;
          &lt;note xml:id="c5-note-0003"&gt;text&lt;/note&gt;
        &lt;/figure&gt;
        &lt;note xml:id="c5-note-0002"&gt;text&lt;/note&gt;
      &lt;/p&gt;
      &lt;tabular&gt;
        &lt;note xml:id="c5-note-0004" numbered="no"&gt;text&lt;/note&gt;
      &lt;/tabular&gt;
      &lt;p&gt;
        some text
        &lt;link&gt;3&lt;/link&gt;
        &lt;notegroup&gt;
          &lt;note xml:id="c5-note-0006"&gt;text&lt;/note&gt;
        &lt;/notegroup&gt;
        &lt;note xml:id="c5-note-0005"&gt;text&lt;/note&gt;
      &lt;/p&gt;
      &lt;p&gt;
        some text
        &lt;link&gt;4&lt;/link&gt;
        &lt;note xml:id="c5-note-0007"&gt;text&lt;/note&gt;
      &lt;/p&gt;
      &lt;/body&gt;
    &lt;/root&gt;
  </code></pre>
  
  <p>my expected output is,</p>
  
  <pre><code>  &lt;root&gt;
      &lt;header&gt;
        some nodes
      &lt;/header&gt;
      &lt;body&gt;
        &lt;p&gt;
          some text
          &lt;link&gt;1&lt;/link&gt;
          &lt;note xml:id="c5-note-0001" numbered="no"&gt;text&lt;/note&gt;
        &lt;/p&gt;
        &lt;p&gt;
          some text
          &lt;link&gt;2&lt;/link&gt;
          &lt;figure&gt;
              &lt;note xml:id="c5-note-0003"&gt;text&lt;/note&gt;
          &lt;/figure&gt;
          &lt;notenum&gt;1&lt;/notenum&gt;
        &lt;/p&gt;
        &lt;tabular&gt;
          &lt;note xml:id="c5-note-0004" numbered="no"&gt;text&lt;/note&gt;
        &lt;/tabular&gt;
        &lt;p&gt;
          some text
          &lt;link&gt;3&lt;/link&gt;
          &lt;notegroup&gt;
            &lt;note xml:id="c5-note-0006"&gt;text&lt;/note&gt;
          &lt;/notegroup&gt;
          &lt;notenum&gt;2&lt;/notenum&gt;
        &lt;/p&gt;
        &lt;p&gt;
          some text
          &lt;link&gt;4&lt;/link&gt;
          &lt;notenum&gt;3&lt;/notenum&gt;
        &lt;/p&gt;
        &lt;newnote&gt;
          &lt;note xml:id="c5-note-0002"&gt;text&lt;/note&gt;
          &lt;note xml:id="c5-note-0005"&gt;text&lt;/note&gt;
          &lt;note xml:id="c5-note-0007"&gt;text&lt;/note&gt;
        &lt;/newnote&gt;
      &lt;/body&gt;
    &lt;/root&gt;
  </code></pre>
  
  <p>i need to create a new node <code>newnote</code> before the end of body tag and cut and paste the <code>note</code> node into that and need to generate a <code>notenum</code> node instead of that <code>note</code>. </p>
  
  <p>i need to do this only within the <code>p</code> node. if the <code>note</code> comes under <code>tabular</code>, <code>figure</code> and <code>notegroup</code> then no need to do anything.</p>
  
  <p>if <code>note</code> contains attribute like <code>numbered="no"</code> then no need to do anything.</p>
  
  <p>i am using the following xslt(just to show the template match that i am using),</p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="utf-8"?&gt;
     &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
    &gt;
        &lt;xsl:output method="xml" indent="yes"/&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:template match ="figure"&gt;
        some operation
      &lt;/xsl:template&gt;
      &lt;xsl:template match ="tabular"&gt;
        some operation
      &lt;/xsl:template&gt;
      &lt;xsl:template match ="notegroup"&gt;
        some operation
      &lt;/xsl:template&gt;
    &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>thanks in advance.</p>