title: XSL sort elements depending on attribute with exception of specific elements
body: <p>I already have a XSL that sorts my whole Document depending on the attribute values @id or @category. Now i want to enhance it by defining nodes that never should be sorted.</p>
  
  <p>Here is a sample XML:</p>
  
  <pre><code>&lt;root&gt;
      [several levels of xml open]
  
      &lt;elemetsToBeSorted&gt;
          &lt;sortMe id="8" /&gt;
          &lt;sortMe id="2" /&gt;
          &lt;sortMe id="4" /&gt;
      &lt;/elemetsToBeSorted&gt;
  
      &lt;elemetsNOTToBeSorted&gt;
          &lt;dontSortMe id="5" /&gt;
          &lt;dontSortMe id="3" /&gt;
          &lt;dontSortMe id="2" /&gt;
      &lt;/elemetsNOTToBeSorted&gt;
  
      [several levels of xml closing]
  &lt;/root&gt;
  </code></pre>
  
  <p>This is my XSL:</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  
  &lt;xsl:output method="xml" indent="yes" /&gt;
  
  &lt;!-- Sort all Elements after their id or category --&gt;
  &lt;xsl:template match="@* | node()"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:apply-templates select="@* | node()"&gt;
              &lt;xsl:sort select="@id" /&gt;
              &lt;xsl:sort select="@category" /&gt;
          &lt;/xsl:apply-templates&gt;
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  
  
  &lt;!-- Next two templates clean up formatting after sorting --&gt;
  &lt;xsl:template match="text()[not(string-length(normalize-space()))]" /&gt;
  
  &lt;xsl:template match="text()[string-length(normalize-space()) &gt; 0]"&gt;
      &lt;xsl:value-of select="translate(.,'&amp;#xA;&amp;#xD;', '  ')" /&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p></p>
  
  <p>Expected Ouput:</p>
  
  <pre><code>&lt;root&gt;
      [several levels of xml open]
  
      &lt;elemetsToBeSorted&gt;
          &lt;sortMe id="2" /&gt;
          &lt;sortMe id="4" /&gt;
          &lt;sortMe id="8" /&gt;
      &lt;/elemetsToBeSorted&gt;
  
      &lt;elemetsNOTToBeSorted&gt;
          &lt;dontSortMe id="5" /&gt;
          &lt;dontSortMe id="3" /&gt;
          &lt;dontSortMe id="2" /&gt;
      &lt;/elemetsNOTToBeSorted&gt;
  
      [several levels of xml closing]
  &lt;/root&gt;
  </code></pre>
  
  <p>How can i achieve that my XSL ignores the "elementsNOTToBeSorted" ?</p>
  
  <p>EDIT:
  I have hundreds of elements that should be sorted, but only a few elements (and its childs) that should not be sorted. So logic would be something like "sort all, except a and b"</p>