[xquery-talk] sorting problem

Rademacher, Gunther Gunther.Rademacher at softwareag.com
Wed May 25 04:06:19 PDT 2011


It can be done using tokenize() and matches() by directly translating your requirements into a list of ordering specifications:

    for $string in
    (
      "11 Aug. 2°",
      "10 Aug. 4°",
      "3.1.1 Aug. 2°",
      "A Aug. 2°",
      "1 Weiss."
    )
    order by
      tokenize($string, " ")[2],
      tokenize($string, " ")[3],
      matches($string, "^[A-Za-z]") descending,
      number(tokenize($string, "[. ]")[1])
    return $string




Software AG - Group Executive Board: Karl-Heinz Streibich (Vorsitzender/Chairman), Arnd Zinnhardt, Mark Edwards, David Broadbent, Dr. Hans Kraus, Dr. Wolfram Jost, Kamyar Niroumand, Ivo Totev 

Sitz/Registered office: Uhlandstraße 12, 64297 Darmstadt, Germany, - Registergericht/Commercial register: Darmstadt HRB 1562 - Vorstand/ Management Board: Karl-Heinz Streibich (Vorsitzender/Chairman), David Broadbent, Dr. Wolfram Jost, Arnd Zinnhardt; - Aufsichtsratsvorsitzender/ Chairman of the Supervisory Board: Dr. Andreas Bereczky - http://www.softwareag.com/
-----Original Message-----

From: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] On Behalf Of Torsten Schassan
Sent: Tuesday, May 24, 2011 15:58
To: XQuery Mailingliste
Subject: [xquery-talk] sorting problem

Hi


considered strings like these:

11 Aug. 2°
10 Aug. 4°
3.1.1 Aug. 2°
A Aug. 2°
1 Weiss.


How would I sort them using XQuery according to this succession

- letters in the middle first (Aug etc)
- the sizes (2° etc)
- "front" letters before numbers
- numbers according to their position before the dots


Sorting result for the examples above would then be:

A Aug. 2°
3.1.1 Aug. 2°
11 Aug. 2°
10 Aug. 4°
1 Weiss.



Would that be done best with tokenize() or matches()?











More information about the talk mailing list