Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's not pretty but you can use the xalan:nodeset function to "pre-process" the numbers into a nodeset with an easily sortable expression as described by Jim. </p> <p>This example works for me with Xalan 2.5.1:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xalan="http://xml.apache.org/xalan"&gt; &lt;xsl:output method="xml" indent="yes" /&gt; &lt;xsl:template match="/"&gt; &lt;root&gt; &lt;!-- Create a sort node with a sort expression wrapping each ROW --&gt; &lt;xsl:variable name="nodes"&gt; &lt;xsl:for-each select="/root/ROW"&gt; &lt;xsl:variable name="sort-string"&gt; &lt;xsl:call-template name="create-sort-string"&gt; &lt;xsl:with-param name="sort-string" select="text()" /&gt; &lt;/xsl:call-template&gt; &lt;/xsl:variable&gt; &lt;sort sort-by="{$sort-string}"&gt; &lt;xsl:copy-of select="." /&gt; &lt;/sort&gt; &lt;/xsl:for-each&gt; &lt;/xsl:variable&gt; &lt;!-- Now sort the sort nodes and copy out the ROW elements --&gt; &lt;xsl:for-each select="xalan:nodeset($nodes)/sort"&gt; &lt;xsl:sort select="@sort-by" data-type="text" /&gt; &lt;xsl:copy-of select="*" /&gt; &lt;/xsl:for-each&gt; &lt;/root&gt; &lt;/xsl:template&gt; &lt;xsl:template name="create-sort-string"&gt; &lt;xsl:param name="sort-string" /&gt; &lt;!-- Biggest number at each level --&gt; &lt;xsl:variable name="max-num" select="1000" /&gt; &lt;xsl:choose&gt; &lt;xsl:when test="contains($sort-string, '.')"&gt; &lt;xsl:value-of select="$max-num + number(substring-before($sort-string, '.'))" /&gt; &lt;xsl:call-template name="create-sort-string"&gt; &lt;xsl:with-param name="sort-string" select="substring-after($sort-string, '.')" /&gt; &lt;/xsl:call-template&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:value-of select="concat($max-num + number($sort-string), '0')" /&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; </code></pre> <p></p> <p>I personally think writing an extension function would be preferable, but I know that's it's not always an option.</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