Re: [xsl] Problem sorting incoming node list

Subject: Re: [xsl] Problem sorting incoming node list
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 8 May 2019 20:47:54 -0000
On 08.05.2019 19:18, Michael Kay mike@xxxxxxxxxxxx wrote:
I haven't had a chance to study all of this, but please note that if you
want to use the XPath 3.1 function then you should be using a more recent
Saxon release than 9.3. The current version is 9.9. Also, only the 1-argument
version of sort() will work in Saxon-HE; the more useful versions of the
function (that allow a user-defined sort key) are higher order functions and
therefore require Saxon-PE or Saxon-EE. The syntax would be

<xsl:for-each-group select=bsort(entry[location=$undulator],
function($entry) {data($entry/(isodate,time))})"
group-by="statistics_category">

To do it with HE you could implement a sort function with xsl:function
based on xsl:perform-sort e.g. declare some namespace for your function
xmlns:mf="http://example.com/mf"; and define

<xsl:function name="mf:sort-entries" as="element(entry)*">
  <xsl:param name="entries" as="element(entry)*"/>
  <xsl:perform-sort select="$entries">
    <xsl:sort select="isodate"/>
    <xsl:sort select="time"/>
  </xsl:perform-sort>
</xsl:function>

then you can use

  <xsl:for-each-group
select="mf:sort-entries(entry[location=$undulator])" group-by="..."

Current Thread