Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>The simplest solution</h2> <p>Simply remove <code>data-type="number"</code>.</p> <p>Your example will sort just fine as text (which is the default). In general, simply sorting as text is probably <strong>the best approach</strong>. XSLT 1.0 does not handle arbitrary data transformations very well, and if you try to use it as a "general" string processor, you'll end up with large, complex, hard to maintain transformations. </p> <p>If you <em>do</em> sort as text, you'll need to ensure all numbers are padded with 0's on the left to the same length. All letters must be in the same case (which is almost always true anyhow, but might break if you combine data from different sources.) Usually, these requirements are easy to meet outside of XSLT.</p> <h2>A slightly more general and longer solution</h2> <p>The xslt-function <code>translate(my-xpath-expr,'abcdef','ABCDEF')</code> could be used to transform mixed-case hexadecimals into upper-case hexadecimals. This probably isn't necessary, usually.</p> <p><em>If</em> you don't know the length of the hexadecimal number you can prepend '0' as dimitre's solution shows, but you can often get away with a simpler trick:</p> <pre><code>&lt;xsl:sort select="string-length(Generation/Sirio/Code)" data-type="number"/&gt; &lt;xsl:sort select="translate(Generation/Sirio/Code,'abcdef','ABCDEF')"/&gt; </code></pre> <p>This works so long as smaller numbers are never longer than larger numbers. It also works if the numbers may contain spaces or are prefixed by "<code>0x</code>".</p> <p>However, if possible, you're best off simply ensuring all numbers are formatted identically and sorting by text - KISS where possible.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload