xsl-list
[Top] [All Lists]

Re: Unusual Sort

2005-04-13 07:47:53
Williamson, Chris wrote:

I was wondering if there is any way to sort elements other than just the
regular alphabetical order.  For example,  If you wanted to sort grade
levels (Freshman, Sophmore, Junior, etc)  so that they are displayed in the
correct order and not the alphabetical order (Freshman, Graduate, Junior,
Senior, Sophmore). This is an optional piece of my application so if It
can't be done fairly easily I will probably not worry about creating the
functionality of the sort on page..in other words if it's a huge deal don't
worry about going to the trouble of creating the sort..

In simple cases you can define lookup table in your document that will map your values to sort values. E.g.

<g:grades>
  <grade sortas="1">Freshman</grade>
  <grade sortas="2">Sophmore</grade>
  ...
</g:grade>

And then translate grade text to ordinal number:
....
<xsl:sort select="document('')//g:grades/grade[. = current()/grade]/@sortas" data-type="number"/>
....

                                Jirka

--
------------------------------------------------------------------
  Jirka Kosek     e-mail: jirka(_at_)kosek(_dot_)cz     http://www.kosek.cz
------------------------------------------------------------------
  Profesionální školení a poradenství v oblasti technologií XML.
     Podívejte se na náš nově spuštěný web http://DocBook.cz
       Podrobný přehled školení http://xmlguru.cz/skoleni/
------------------------------------------------------------------

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

<Prev in Thread] Current Thread [Next in Thread>