473,513 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with xsl:sort

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
Oct 13 '06 #1
12 1889
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
Oct 13 '06 #2
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
Oct 13 '06 #3
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
Oct 13 '06 #4
In article <eg**********@gemini.csx.cam.ac.uk>,
Tom Wright <te***@spam.ac.ukwrote:
>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
Oct 13 '06 #5
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
Oct 13 '06 #6
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
Oct 13 '06 #7
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
Oct 13 '06 #8
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
Oct 13 '06 #9

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 '06 #10
In article <eg**********@gemini.csx.cam.ac.uk>,
Tom Wright <te***@spam.ac.ukwrote:
>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
Oct 13 '06 #11
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
Oct 13 '06 #12
p.*****@ctncorp.com 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
Oct 13 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1910
by: Jarle Presttun | last post by:
Hi, Sometimes I display values by combining information from different sections in the xml, like I do with gradeText in the student template bellow. Is it possible to sort on gradeText when I loop over students, as shown in the example? If not, I would have to modify some sql's. Thanks, Jarle. XML:
1
1805
by: | last post by:
Example XML: <?xml version="1.0" encoding="UTF-8" ?> <root> <foo> <index>1></index> <bar> <child /> <child /> </bar> </foo>
1
2053
by: Derek Tinney | last post by:
Hi, I'm having difficulty building an XLST file that allows me to sort a list of log records. I put together an XSL file that allows me to output a copy of the input file and then I attempted to sort it. Eventually I want to filter it based on the "when" element (and/or others) but I cannot proceed until I get the sort to work. I have...
2
2544
by: R | last post by:
Hello everybody. I was sorting all my XML data with for-each and sort. But there were few cases that I didn't want to sort my data. so I added nosort attribute - if given and set to '1' don't sort. I wrote this: <xsl:for-each select="field">
6
2142
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows XP Pro SP 1, .Net Framework 1.1) and on our production server (Windows 2K SP 4, .Net Framework 1.1). I have simplified the code and data to isolate...
2
2862
by: jobooker | last post by:
I'm having issues sorting. The short description is, how do I set the select attribute of xsl:sort to be the value of an xsl:variable? The longer description follows: What I want to do is to be able to make a data table sortable by different headers. Right now, I've got javascript that lets you click on a column header, and then it changes...
3
3485
by: davisford | last post by:
Hi, If I have something like this: <parents> <parent name="foo"> <children> <child>fred</child> <child>barney</child> <child>wilma</child>
2
2163
by: ajc308 | last post by:
I have an XML document that looks like the following: <root name="PlanRepository"> <directory name="connoraj"> <directory name="single_run1"> <file>insidebox.txt</file> <file>outsidebox.txt</file> <directory name="SAFE_Input"> <file>leapseconds.txt</file>
7
5086
by: otis | last post by:
Hi all, This is a small issue to make things prettier, but we all know how important that can be! I had an xsl:if to check if a node was the last one in a collection of nodes and if it was a horizontal divider would not be displayed underneath it. This worked a treat but now I'm trying to sort my data using xsl:sort. The if statement...
0
7394
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7559
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5701
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4756
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.