• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

xsl - sorting multiple fields

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks heaps Mapraputa, it works :-)
 
I was her plaything! And so was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic