Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>This transformation</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:variable name="vZeroes" select="'00000000000000000000000000000000000000'"/&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="/*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="*"&gt; &lt;xsl:sort select= "concat(substring($vZeroes, 1, string-length($vZeroes) - string-length(@hexVal) ), translate(@hexVal,'abcdef','ABCDEF') ) "/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on this XML document:</strong></p> <pre><code>&lt;t&gt; &lt;x hexVal="0A"/&gt; &lt;x hexVal="0327FE"/&gt; &lt;x hexVal="ff5240"/&gt; &lt;x hexVal="1BA402"/&gt; &lt;x hexVal="C3A214"/&gt; &lt;/t&gt; </code></pre> <p><strong>produces the wanted, correct result:</strong></p> <pre><code>&lt;t&gt; &lt;x hexVal="0A"/&gt; &lt;x hexVal="0327FE"/&gt; &lt;x hexVal="1BA402"/&gt; &lt;x hexVal="C3A214"/&gt; &lt;x hexVal="ff5240"/&gt; &lt;/t&gt; </code></pre> <p><strong>Solution details</strong>:</p> <p>The only assumption this solution makes is that the maximum length of the hexadecimal sort keys is limited (say to 20). Then we are using a string of zeroes, longer than this maximum length. The <code>$vZeroes</code> variable holds this string of zeroes and is used in padding every sort key to the left with zeroes, so that all sort keys have the same length.</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