title: How to sort a subelement of XML with XSLT
body: <p>I have an input XML file which I need to copy 1:1 to the output, except for one subelement which contains subitems that need to be sorted.</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;top&gt;
    &lt;elementA /&gt;
    &lt;elementB /&gt;
    &lt;contents&gt;
        &lt;contentitem&gt;
            &lt;id&gt;3&lt;/id&gt;
            &lt;moretags1 /&gt;
            &lt;moretags2 /&gt;
        &lt;/contentitem&gt;
        &lt;contentitem&gt;
            &lt;id&gt;2&lt;/id&gt;
            &lt;moretags1 /&gt;
            &lt;moretags2 /&gt;
        &lt;/contentitem&gt;
        &lt;contentitem&gt;
            &lt;id&gt;1&lt;/id&gt;
            &lt;moretags1 /&gt;
            &lt;moretags2 /&gt;
        &lt;/contentitem&gt;
    &lt;/contents&gt;
  &lt;/top&gt;
  </code></pre>
  
  <p>I'd like an XSL Transformation that puts the "contentitem" elements in order, sorted by their "id" elements.
  All other tags, including nested ones, must be copied verbatim. I already tried with xsl:copy, but either I get double contents or something turns out missing.</p>