Help with xsl:sort

Discussion in 'XML' started by Tom Wright, Oct 13, 2006.

  1. Tom Wright

    Tom Wright Guest

    Hi all

    I'm using the following code with Apache and mod-xslt but it's not sorting
    the elements as I want it to. At the moment, it sorts them with all items
    starting with an uppercase letter first, like this:
    A B C a b c

    no matter what the setting of the case-order attribute is. It
    rather looks like it's sorting them by ASCII (or unicode..?)
    character order, rather than according to the language setting.

    The lang attribute should be inferred automatically from the
    system environment, but even if it is set manually (to "en-GB"),
    the sort still does not work as expected.

    According to the manual, with the attribute set to upper-first, it should do
    this:
    A a B b C c
    ....and with it set to lower-first, it should do this:
    a A b B c C


    Here's the code:

    <xsl:apply-templates select="bookmark|alias[name(id(@ref)) = 'bookmark']"
    mode="main">
    <xsl:sort select="concat(title,id(@ref)/title)" lang="en-GB"/>
    </xsl:apply-templates>

    Thanks!

    --
    I'm at CAMbridge, not SPAMbridge
    Tom Wright, Oct 13, 2006
    #1
    1. Advertising

  2. Is there a reason you're trying to imply this using language, rather
    than using the case-order attribute which is specifically intended for
    the purpose?

    http://www.w3.org/TR/xslt#sorting

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Oct 13, 2006
    #2
    1. Advertising

  3. Tom Wright

    Tom Wright Guest

    Joe Kesselman wrote:
    > Is there a reason you're trying to imply this using language, rather
    > than using the case-order attribute which is specifically intended for
    > the purpose?


    Sorry, I should've explained better. I've tried doing it with just lang,
    with just case-order and with both specified but none of it makes any
    difference to the final sorting order. Is this a bug in mod-xslt?

    --
    I'm at CAMbridge, not SPAMbridge
    Tom Wright, Oct 13, 2006
    #3
  4. Tom Wright

    Tom Wright Guest

    To clarify, I've tried using sort with each of its various options (as
    listed on http://www.w3.org/TR/xslt#sorting), but no matter what I do it
    always sorts the items like this:

    A B C a b c

    That's not a correct sorting order by any definition that I've seen.

    I don't really mind whether it sorts upper case items before or after lower
    case, but I would like it to sort all items beginning with an "A" of either
    case before all items beginning with a "B" of either case. Either of the
    following would be fine:

    A a B b C c
    a A b B c C

    I hope that makes it a bit clearer - sorry, I didn't explain very well the
    first time around.

    --
    I'm at CAMbridge, not SPAMbridge
    Tom Wright, Oct 13, 2006
    #4
  5. In article <ego3pe$9nj$>,
    Tom Wright <> wrote:

    >To clarify, I've tried using sort with each of its various options (as
    >listed on http://www.w3.org/TR/xslt#sorting), but no matter what I do it
    >always sorts the items like this:
    >
    > A B C a b c


    Have you tried the same code with some other stylesheet processor?

    -- Richard
    Richard Tobin, Oct 13, 2006
    #5
  6. Tom Wright wrote:
    > A B C a b c
    > That's not a correct sorting order by any definition that I've seen.


    Correct by ASCII (or Unicode) character order...

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Oct 13, 2006
    #6
  7. Tom Wright

    Tom Wright Guest

    Joseph Kesselman wrote:
    > Tom Wright wrote:
    >> A B C a b c
    >> That's not a correct sorting order by any definition that I've seen.

    >
    > Correct by ASCII (or Unicode) character order...


    Yes ok, but that's not "culturally correct" as per the specs, and it's not
    what any non-techie counts as a sensible sorting order.


    --
    I'm at CAMbridge, not SPAMbridge
    Tom Wright, Oct 13, 2006
    #7
  8. Tom Wright wrote:
    > Sorry, I should've explained better. I've tried doing it with just lang,
    > with just case-order and with both specified but none of it makes any
    > difference to the final sorting order. Is this a bug in mod-xslt?


    Certainly sounds like it. Try other processors.

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Oct 13, 2006
    #8
  9. Tom Wright

    Tom Wright Guest

    Richard Tobin wrote:
    > Have you tried the same code with some other stylesheet processor?


    Good plan - I didn't have any others on the machine, but have just installed
    xalan and it gives the same output (mod-xslt is based on libxslt and xalan
    is based on libxalan)

    If anyone knows of another xslt processor which does sorting correctly, I'd
    like to try it out.

    --
    I'm at CAMbridge, not SPAMbridge
    Tom Wright, Oct 13, 2006
    #9
  10. Tom Wright

    Guest

    Tom Wright wrote:
    > Richard Tobin wrote:


    [sorting problems - A a B b C c sort order wanted]

    > > Have you tried the same code with some other stylesheet
    > > processor?

    >
    > Good plan - I didn't have any others on the machine, but
    > have just installed xalan and it gives the same output
    > (mod-xslt is based on libxslt and xalan is based on
    > libxalan)
    >
    > If anyone knows of another xslt processor which does
    > sorting correctly, I'd like to try it out.


    How about using translate(), at least as a temporary
    solution? It won't sort A and a, obviously, but at least
    you'll get a A A a B b B C C c C etc., which is better than
    nothing imho.

    --
    Pavel Lepin
    , Oct 13, 2006
    #10
  11. In article <ego5cs$cbt$>,
    Tom Wright <> wrote:
    >If anyone knows of another xslt processor which does sorting correctly, I'd
    >like to try it out.


    I'm surprised Xalan doesn't, but you should try Saxon and even xt.

    -- Richard
    Richard Tobin, Oct 13, 2006
    #11
  12. Tom Wright

    Tom Wright Guest

    Richard Tobin wrote:
    > I'm surprised Xalan doesn't, but you should try Saxon and even xt.


    Saxon works! My distribution doesn't seem to include a packaged copy of xt,
    so I'll skip that one. Thanks though, I've got something that works at
    least. Not sure how to integrate it with Apache, but I'll investigate that
    separately.


    --
    I'm at CAMbridge, not SPAMbridge
    Tom Wright, Oct 13, 2006
    #12
  13. Tom Wright

    Tom Wright Guest

    wrote:
    > How about using translate(), at least as a temporary
    > solution? It won't sort A and a, obviously, but at least
    > you'll get a A A a B b B C C c C etc., which is better than
    > nothing imho.


    Yes, that works. Thanks, I was unaware of XSLT's translate() function. Now
    I just have to decide whether it's better to install Saxon or use this
    workaround. Thanks for your help, everyone.

    Tom


    --
    I'm at CAMbridge, not SPAMbridge
    Tom Wright, Oct 13, 2006
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nobody
    Replies:
    0
    Views:
    534
    nobody
    Jun 1, 2004
  2. Replies:
    1
    Views:
    3,595
    A. Bolmarcich
    May 27, 2005
  3. Replies:
    2
    Views:
    9,259
    Martin Honnen
    Sep 5, 2006
  4. Navin
    Replies:
    1
    Views:
    684
    Ken Schaefer
    Sep 9, 2003
  5. GIMME
    Replies:
    5
    Views:
    184
    Thomas 'PointedEars' Lahn
    Jul 26, 2004
Loading...

Share This Page