This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes xsl - sorting multiple fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xsl - sorting multiple fields" Watch "xsl - sorting multiple fields" New topic
Author

xsl - sorting multiple fields

bill gee
Greenhorn

Joined: Dec 26, 2002
Posts: 1
My question is how to do multi sorting fields. For example:
<category>
<subcat>
<type>tablet</type>
<name>panadol</name>
<subcat>
<subcat>
<type>tablet</type>
<name>panamax</name>
</subcat>
<subcat>
<type>something</type>
<name>blah blah blah</name>
</subcat>
........
</category>
The expected result is:
1. tablet
a. panadol
b. paramax
2. something
a. blah blah blah
Please help! and apologise if my question is already posted previously.
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
In case you ask for XSLT solution, you normally just have several <xsl:sort> statements, like
<xsl:for-each select="...">
<xsl:sort select="someField"/>
<xsl:sort select="anotherField"/>
...
</xsl:for-each>


Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Trina Thach
Greenhorn

Joined: Jun 12, 2001
Posts: 18
I want to ask the same question as above with extra requirements...That is how to select DISTINCT <type> content and display all relevant of <name> under each type, and both elements must be sorted alphabetically...
I have tried your solution above and it wouldn't work at all. I manage to display Distinct <type> by using <xsl:if> to compare the current node with the preceeding node (after sorting of course) but the <name> just wouldn't be sorted at all.
Any suggestion? Thanks...
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
This is more complicated. You need to use the horrendous Muenchian method Adapted for our example version will be like

[ December 27, 2002: Message edited by: Mapraputa Is ]
Trina Thach
Greenhorn

Joined: Jun 12, 2001
Posts: 18
Thanks heaps Mapraputa, it works :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xsl - sorting multiple fields
 
Similar Threads
how to put a counter in XSL
dynamic input fields
Can't pass changed beans values from one JSP page to another
How To Make the "Browse ..." Button Work?
Navigate from one JSP to another