title: Ordering by a sequence of values in XQuery
body: <p>I've got some XML data that takes this form:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;products&gt;
    &lt;product version="1.2.3"/&gt;
    &lt;product version="1.10.0"/&gt;
    &lt;product version="2.1.6"/&gt;
  &lt;/products&gt;
  </code></pre>
  
  <p>...And so on. I want to order these in XQuery by version number. Trouble is, if I just do <code>order by $thing/@version</code>, it does a lexicographic comparison that puts 1.10.0 before 1.2.3, which is wrong.</p>
  
  <p>What I really want to do is something like:</p>
  
  <pre><code>order by tokenize($thing/@version, '\.') ! number(.)
  </code></pre>
  
  <p>Unfortunately this doesn't work because XQuery doesn't let you use an entire sequence as an ordering key. How can I get something like this?</p>
  
  <p>A solution that doesn't rely on all the version numbers having the same number of dots would be preferable, but I'll take what I can get.</p>