Case insensitive sorting

Bill Gee bgee at campercaver.net
Wed May 3 14:03:45 BST 2023


Hmmm...  I did a bit of research on the xsl:sort function.  It does 
appear this could be a difficult nut to crack.

I found one suggestion to use a lower-case() function, as this:

<xsl:sort lang="$lang" select="lower-case(@title)"/>

I tried that but got only a blank report.  One source I found for this 
says that lower-case() is not available in xsl 1.0.  I do not know which 
version I have (Fedora 38, by the way).  If not available, I would have 
expected an error.  Instead I got nothing.

I then put in your suggestion from below which works perfectly.  It 
produces the report I want.  It is not an ideal solution for two 
reasons.  First, it will go away when the next Tellico upgrade is 
installed.  Second, it gives no option to use case-sensitive sorting if 
that is wanted.

The ideal solution would be to amend the xsl:sort function to take a 
third option "case-order=ignore".  Probably not going to happen and 
certainly not under control of anyone here!

It might be interesting to have a selection in the Settings menu for 
lower-case first, or upper-case first.  That could then be passed as a 
parameter to xsl:sort.  If "ignore" is ever implemented, then it would 
be easy to add to the settings.  It might also be a useful new feature 
to have a Settings item for either ascending or descending sort order.

Your comment about non-English characters is a good one.  I have many of 
them in my database.  As far as I can see, though, the first letter of 
every artist name is an English character.  A few examples ...

Alfvén, Hugo
Albéniz, Isaac
Bartók, Béla

All of these sort in the order I expect.  Bartók comes after Bart, 
Lionel and before Basie, Count.  I have a few artists where the second 
character is a ', such as D'Rivera and d'Indy.  These sort as expected, 
coming before da Milano and Dalton

So far I do not have any artists with non-Latin names.  No Chinese or 
Japanese or Cyrillic characters - yet!  :-)

It occurs to me that this same problem may extend to other reports and 
fields.  Track titles, for example ...  I do not see a report that will 
list track titles, but if there were one it would find hundreds of 
non-English characters in my database.  Sorting those could be interesting!

===============
Bill Gee

On 5/2/23 20:59, Robby Stephenson wrote:
> On Tue, May 2, 2023 at 4:57 PM Bill Gee <bgee at campercaver.net 
> <mailto:bgee at campercaver.net>> wrote:
> 
>     Is there a way to produce reports where the sorting is case INsensitive?
> 
> 
> The sorting uses XSL which is language dependent, and for english, at 
> least, seems to default to what you note, that lower-case is sorted 
> after upper-case. https://www.w3schools.com/xml/ref_xsl_el_sort.asp 
> <https://www.w3schools.com/xml/ref_xsl_el_sort.asp>
> 
> I'll see if I can find some sort of solution or option. In the 
> mean-time, if you make a copy of the Group_View.xsl file in the 
> report-templates folder, and edit line 153 or thereabouts to change
>      <xsl:sort lang="$lang" select="@title"/>
> to
>      <xsl:sort lang="$lang" select="translate(@title,
>                                               'abcdefghijklmnopqrstuvwxyz',
>                                              
>   'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
> that will convert all the lower-case characters to upper-case before 
> sorting. Obviously, that only works for the 26 ascii characters 
> represented there, but at least it's a workaround.
> 
> Robby


More information about the tellico-users mailing list