Re: Custom sorting through xslt extension object

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Dimitre Novatchev [MVP XML] (dnovatchev_at_yahoo.com)
Date: 03/30/04


Date: Tue, 30 Mar 2004 09:22:26 +0200


"Jiho Han" <jiho.han@infinityinfo.com> wrote in message
news:%239ZICMdFEHA.3448@TK2MSFTNGP09.phx.gbl...
> I don't have a source xml but let me give you a scenario.
> Let's say we have an xml like:
>
> <persons>
> <person>
> <lastname>Smith</lastname>
> <firstname>John</firstname>
> <favoritecolor>red</favoritecolor>
> </person>
> <person>
> <lastname>Doe</lastname>
> <firstname>Jane</firstname>
> <favoritecolor>blue</favoritecolor>
> </person>
> <person>
> <lastname>Cooke</lastname>
> <firstname>Robin</firstname>
> <favoritecolor>yellow</favoritecolor>
> </person>
> </persons>
>
> Then say we want to sort the above by <favoritecolor> element values.
> However, the sorting mechanism won't be alphabetical. For
<favoritecolor>,
> proper ascending order is from warmest color to the coolest color: red,
> orange, yellow, green, blue, indigo, purple, etc. As you can see, I came
up
> with the sorting order - based on rainbow colors. Really, the desired
> sorting order may be defined by the application arbitrarily. I am
guessing
> that this kind of sorting can only be achieved by extension objects. Let
me
> know if there is an example similar to the given scenario or any other
> resources that may be usuful for achieving the disired effects.

Yes, see for example "Date Sorting in pure XSLT"
at: http://www.topxml.com/code/default.asp?p=3&id=v20021212030100

As for generic sort in XSLT, see "Sorting with unknown number of sort keys "
at:

http://www.biglist.com/lists/xsl-list/archives/200303/msg00007.html

Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html



Relevant Pages

  • Re: Sorting problem
    ... change the type to int16 for the appropriate node or read in the xml as ... Because when sorting, different data type has ... >>> DataColumns' DAtaType in the DataTable. ...
    (microsoft.public.dotnet.framework.aspnet.datagridcontrol)
  • Re: XML Collating sequence
    ... Just to add to what Bob said, XML uses binary comparisons for comparison and sorting. ... Efficient, but does not account for the little things we've grown accustomed to like dictionary sorting, accent insensitivity, case insensitivity, etc. ... Case sensitivity, Accent sensitivity? ...
    (microsoft.public.sqlserver.xml)
  • Re: Custom sorting through xslt extension object
    ... I don't have a source xml but let me give you a scenario. ... the sorting mechanism won't be alphabetical. ... sorting order may be defined by the application arbitrarily. ...
    (microsoft.public.dotnet.xml)
  • Re: sorting a dataset
    ... Ideally, I would like to return the data in structured hierarchical xml, eg: ... I know I can copy my dataset into a dataview and sort the ... >> are sorting a dataview. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: sorting a dataset
    ... Ideally, I would like to return the data in structured hierarchical xml, eg: ... I know I can copy my dataset into a dataview and sort the ... >> are sorting a dataview. ...
    (microsoft.public.dotnet.xml)