XSLT: Dynamic sorting with multiple keys

Discussion in 'XML' started by Petr Vlcek, Jul 19, 2005.

  1. Petr Vlcek

    Petr Vlcek Guest

    Hello,

    I have a file with records storing information about people, something
    like this:

    <people>
    <person>
    <name>John</name>
    <name>Fitzgerald</name>
    <name>Kennedy</name>
    </person>

    <person>
    <name>George</name>
    <name>Walker</name>
    <name>Bush</name>
    </person>

    <person>
    <name>George</name>
    <name>Washington</name>
    </person>
    </people>

    I have tried to write XSLT template that would sort records by name. When
    first names are the same, it would sort by second name, etc. The problem
    is, that records can differ with number of names.

    For fixed number of names (here it is 2) it is possible to use this
    template:

    <xsl:sort select="name[1]"/>
    <xsl:sort select="name[2]"/>

    Does anyone have an idea how to do it for dynamic number of names?

    Thanks in advance, Petr Vlcek.
    Petr Vlcek, Jul 19, 2005
    #1
    1. Advertising

  2. Re: Dynamic sorting with multiple keys

    "Petr Vlcek" <> wrote in message
    news:p...
    > Hello,
    >
    > I have a file with records storing information about people, something
    > like this:
    >
    > <people>
    > <person>
    > <name>John</name>
    > <name>Fitzgerald</name>
    > <name>Kennedy</name>
    > </person>
    >
    > <person>
    > <name>George</name>
    > <name>Walker</name>
    > <name>Bush</name>
    > </person>
    >
    > <person>
    > <name>George</name>
    > <name>Washington</name>
    > </person>
    > </people>
    >
    > I have tried to write XSLT template that would sort records by name. When
    > first names are the same, it would sort by second name, etc. The problem
    > is, that records can differ with number of names.
    >
    > For fixed number of names (here it is 2) it is possible to use this
    > template:
    >
    > <xsl:sort select="name[1]"/>
    > <xsl:sort select="name[2]"/>
    >
    > Does anyone have an idea how to do it for dynamic number of names?
    >
    > Thanks in advance, Petr Vlcek.


    Yes, it has been done -- see it here:

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


    Cheers,
    Dimitre Novatchev
    Dimitre Novatchev, Jul 19, 2005
    #2
    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. Replies:
    2
    Views:
    708
    Henry S. Thompson
    Oct 19, 2005
  2. sandeep Kanwal

    serial keys/validation keys

    sandeep Kanwal, Oct 29, 2004, in forum: C++
    Replies:
    1
    Views:
    578
    Mike Wahler
    Oct 29, 2004
  3. Harry George
    Replies:
    9
    Views:
    690
    sonal
    Jun 13, 2006
  4. Rehceb Rotkiv
    Replies:
    16
    Views:
    873
    Alex Martelli
    Apr 2, 2007
  5. Tom Kirchner

    sorting by multiple criterias (sub-sorting)

    Tom Kirchner, Oct 11, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    466
    Michael Budash
    Oct 11, 2003
Loading...

Share This Page