title: XSLT: Sort by multiple items
body: <p>I have XML data such as:</p>
  
  <pre><code>&lt;feed&gt;
    &lt;entry&gt;
      &lt;id&gt;4&lt;/id&gt;
      &lt;updated&gt;2011-01-18T16:55:54Z&lt;/updated&gt;
      &lt;title&gt;title2&lt;/title&gt;
    &lt;/entry&gt;
    &lt;entry&gt;
      &lt;id&gt;3&lt;/id&gt;
      &lt;updated&gt;2011-01-18T16:55:54Z&lt;/updated&gt;
      &lt;title&gt;title1&lt;/title&gt;
    &lt;/entry&gt;
    &lt;entry&gt;
      &lt;id&gt;2&lt;/id&gt;
      &lt;updated&gt;2011-01-18T16:55:54Z&lt;/updated&gt;
      &lt;title&gt;title1&lt;/title&gt;
    &lt;/entry&gt;
    &lt;entry&gt;
      &lt;id&gt;1&lt;/id&gt;
      &lt;updated&gt;2011-01-18T16:55:54Z&lt;/updated&gt;
      &lt;title&gt;title&lt;/title&gt;
    &lt;/entry&gt;
  &lt;/feed&gt;
  </code></pre>
  
  <p>And I need the outcome to result like:</p>
  
  <pre><code>&lt;feed&gt;
    &lt;entry&gt;
      &lt;id&gt;1&lt;/id&gt;
      &lt;updated&gt;2011-01-18T16:55:54Z&lt;/updated&gt;
      &lt;title&gt;title&lt;/title&gt;
    &lt;/entry&gt;
    &lt;entry&gt;
      &lt;id&gt;2&lt;/id&gt;
      &lt;updated&gt;2011-01-18T16:55:54Z&lt;/updated&gt;
      &lt;title&gt;title1&lt;/title&gt;
    &lt;/entry&gt;
    &lt;entry&gt;
      &lt;id&gt;3&lt;/id&gt;
      &lt;updated&gt;2011-01-18T16:55:54Z&lt;/updated&gt;
      &lt;title&gt;title1&lt;/title&gt;
    &lt;/entry&gt;
    &lt;entry&gt;
      &lt;id&gt;4&lt;/id&gt;
      &lt;updated&gt;2011-01-18T16:55:54Z&lt;/updated&gt;
      &lt;title&gt;title2&lt;/title&gt;
    &lt;/entry&gt;
  &lt;/feed&gt;
  </code></pre>
  
  <p>Basically I need the XSLT to sort on the title, then the ID. I have made an XSLT but the shorter times come out last (using Xerces):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet xmlns:atom="http://www.w3.org/2005/Atom"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;
  &lt;xsl:output method="xml" encoding="UTF-8" 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="atom:feed"&gt;
    &lt;xsl:copy&gt;
     &lt;xsl:apply-templates select="*" /&gt;
     &lt;xsl:for-each select="atom:entry"&gt;
      &lt;xsl:sort select="string-length(atom:title)" order="descending" /&gt;
      &lt;xsl:sort select="atom:title" data-type="text" order="ascending" /&gt;
      &lt;xsl:copy-of select="."/&gt;
     &lt;/xsl:for-each&gt;
    &lt;/xsl:copy&gt;
   &lt;/xsl:template&gt;
  
   &lt;xsl:template match="atom:feed/atom:entry"/&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>