title: Copy all the child elements except one in XSLT without copying whole XML
body: <p>I have searched to copy child elements except one or change the value of the tag. Everywhere below templates are used to copy all the XML and then 
  apply templates to remove one element.</p>
  
  <pre><code>&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="part"/&gt;
  </code></pre>
  
  <p>I have a XML like below</p>
  
  <pre><code>&lt;root&gt;
      &lt;a1&gt;
      ...
      &lt;/a1&gt;
      &lt;a2&gt;
      ....
      &lt;/a2&gt;
      &lt;a3&gt;
          &lt;a31&gt;1&lt;/a31&gt;
          &lt;a32&gt;2&lt;/a32&gt;
          &lt;a33&gt;
              &lt;a331&gt;3&lt;/a331&gt;
              &lt;a332&gt;5&lt;/a332&gt;
              ...
              &lt;a339&gt;10&lt;/a339&gt;
          &lt;/a33&gt;
          &lt;a33&gt;
              &lt;a331&gt;4&lt;/a331&gt;
              &lt;a332&gt;6&lt;/a332&gt;
              ...
              &lt;a339&gt;56&lt;/a339&gt;
          &lt;/a33&gt;
          &lt;a34&gt;
              &lt;a331&gt;3&lt;/a331&gt;
              ....
          &lt;/a34&gt;
      &lt;/a3&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>I have written xslt like this</p>
  
  <pre><code>&lt;xsl:template match="root"&gt;
      &lt;xsl:element name="root"&gt;
          &lt;xsl:apply-templates select="root"/&gt;
      &lt;/xsl:element&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="root"&gt;
      &lt;xsl:element name="a1"&gt;
          &lt;xsl:apply-templates select="a1"/&gt;
      &lt;/xsl:element&gt;
      ...
      &lt;xsl:if test="a3!=''"&gt;
          &lt;xsl:if test="((a3/a33[a331='3']!='') or (a3/a33[a331='3']!=''))"&gt;
              &lt;xsl:element name="a3"&gt;
                  &lt;xsl:apply-templates select="a3"/&gt;
              &lt;/xsl:elememt&gt;
          &lt;/xsl:if&gt;
      &lt;/xsl:if&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="a3" &gt;      
      &lt;xsl:apply-templates select="*[a331='3']" mode="copy"&gt;&lt;/xsl:apply-templates&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="*" mode="copy"&gt;
      &lt;xsl:apply-templates/&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="a331"&gt;
      &lt;xsl:element name="a331"&gt;
          &lt;xsl:value-of select="4"&gt;
      &lt;/xsl:element&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>I would like to get output xml like below.</p>
  
  <pre><code>&lt;root&gt;
      &lt;a1&gt;
      ...
      &lt;/a1&gt;
      &lt;a2&gt;
      ....
      &lt;/a2&gt;
      &lt;a3&gt;
          &lt;a31&gt;1&lt;/a31&gt;
          &lt;a32&gt;2&lt;/a32&gt;
          &lt;a33&gt;
              &lt;a331&gt;4&lt;/a331&gt;
              &lt;a332&gt;5&lt;/a332&gt;
              ...
              &lt;a339&gt;10&lt;/a339&gt;
          &lt;/a33&gt;      
          &lt;a34&gt;
              &lt;a331&gt;4&lt;/a331&gt;
              ....
          &lt;/a34&gt;
      &lt;/a3&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>could you please someone explain how to achieve this without copying whole XML first place?</p>