Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xsl - sorting multiple fields

 
bill gee
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
Trina Thach
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks heaps Mapraputa, it works :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic