XSLT: Dynamic sorting with multiple keys

P

Petr Vlcek

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.
 
D

Dimitre Novatchev

Petr Vlcek said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top