title: XSLT 2.0 - xsl:number inconsistent number order
body: <p>In XSLT 2.0 I am processing tei:xml documents to HTML. During this process I output footnote numbers in two passes, for two reasons.</p>
  
  <p>First, adding numbers in the text body itself by selecting certain elements to which are attached/replaced by <code>&lt;sup&gt;</code> (for superscript numbers).</p>
  
  <p>Second, in the footer <code>div</code> I create a list of those same footnote numbers with various notes.</p>
  
  <p>All of this works great, thanks in large part to the help received <a href="https://stackoverflow.com/questions/52874845/xslt-2-0-moving-a-node-created-in-first-step-of-a-multi-step-transformation">here</a> on SO.</p>
  
  <p>But during testing through the hundreds of documents, I noticed a problem of number order.</p>
  
  <p>The first step outputs the numbers in the <strong>correct order</strong> (lines 9-45). The second step outputs the elements in the <strong>wrong order</strong> (lines 73-99). XSLT fiddle here demonstrates this simply and clearly in HTML view: <a href="https://xsltfiddle.liberty-development.net/jyH9rNj" rel="nofollow noreferrer">https://xsltfiddle.liberty-development.net/jyH9rNj</a></p>
  
  <p>Put in simple comparison, the output looks like this</p>
  
  <pre><code>body footnote #        footnote div footnote #
       1                          3
       2                          1
       3                          2
  </code></pre>
  
  <p>I believe this is a question of order processing, but after attempting to adjust it through <code>modes</code> and <code>priority</code> I have not been able to solve this. It seems to have to do with moving the <code>seg</code> element before giving it a number...</p>
  
  <p>Many, many thanks in advance.</p>
  
  <p>NB: the number for <code>seg/@corresp</code> and <code>date</code> can only ever appear once each per <code>&lt;seg&gt;</code> maximum; <code>note</code> can theoretically appear several times.</p>