Re: [xsl] Multiple Sort Key Components

Subject: Re: [xsl] Multiple Sort Key Components
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 5 Jun 2019 08:27:07 -0000
Your first sort key is position(). Every item in the input has a different
value for position(). The Nth sort key only affects the outcome if all sort
keys before the Nth have duplicate values. When there are no duplicates for
the first sort key, the second and third will therefore have no effect.

Michael Kay
Saxonica

> On 5 Jun 2019, at 00:28, Don Smith dsmith_lockesmith@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Hello,
>
> I'm attempting to sort the content of a variable using multiple sort key
components and my last component (@range_length) doesn't take effect. Given
this input which reflects paragraphs in document order:
>
>  <list_of_group_ranges>
>                         <range comment_id="2"
>                                start_element="d34e70"
>                                end_element="d34e141"
>                                range_length="10"/>
>                         <range comment_id="3"
>                                start_element="d34e70"
>                                end_element="d34e160"
>                                range_length="14"/>
>                         <range comment_id="4"
>                                start_element="d34e70"
>                                end_element="d34e102"
>                                range_length="5"/>
>                         <range comment_id="17"
>                                start_element="d34e174"
>                                end_element="d34e214"
>                                range_length="26"/>
>                         <range comment_id="18"
>                                start_element="d34e174"
>                                end_element="d34e193"
>                                range_length="22"/>
>                         <range comment_id="23"
>                                start_element="d34e203"
>                                end_element="d34e209"
>                                range_length="25"/>
> </list_of_group_ranges>
>
> I want to sort these according to 3 sort components:
> 1. document order
> 2. @start_element value
> 3. @range_length value
>
> The code I'm using to sort is:
>
>                        <xsl:for-each select="$list_of_group_ranges/*">
>                             <xsl:sort select="position()"/>
>                             <xsl:sort select="@start_element"/>
>                             <xsl:sort data-type="number" order="descending"
select="@range_length"></xsl:sort>
>                             <xsl:copy-of select="."/>
>                         </xsl:for-each>
>
> But the last sort component, @range_length, isn't taking effect as the
<range> elements with the same @start_element don't sort according to
@range_length. What am I missing?
>
> Thanks
>
> Don
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by
email <>)

Current Thread