[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Sorting things on two levels


Subject: [xsl] Sorting things on two levels
From: "Michele R Combs mrrothen@xxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 14 Apr 2015 14:49:31 -0000

Apologies if this is a stupidly easy question, but I haven't done a lot with
this particular aspect of XSL, so please be kind!

I'm writing a simple style sheet for DocBook and I need to be able to sort the
index tags twice, once by the first term and once by the second term, so that
main headings and subheadings come out in the correct order.  Not everything
has a subheading.  If a main heading or subheading occurs twice, I need it to
output only once followed by IDs for all the occurrences.

Right now I'm doing the first sort and outputting a document, then processing
that second document to do the second sort.  I need to do it all in one pass.
I'm sure it's possible, I just don't know how to get started.

For those not familiar with DocBook, the tags look like this (ignore the
periods, they're there so that my email doesn't strip out the line breaks):

<indexterm id="{ID}">.
     <primary>bears</primary>.
     <secondary>feeding</secondary>.
</indexterm>.

<indexterm id="{ID}">.
     <primary>bears</primary>.
     <secondary>breeding</secondary>.
</indexterm>.

<indexterm id="{ID}">.
  <primary>bears</primary>.
  <secondary>hunting</secondary>.
</indexterm>.

<indexterm id="{ID}">.
  <primary>aardvarks</primary>.
</indexterm>.

<indexterm id="{ID}">.
     <primary>bears</primary>.
     <secondary>hunting</secondary>.
</indexterm>.


The output from the above should be as follows (I'm wrapping it in HTML list
tags but have omitted them here for clarity -- I assume if I can get the sort
working I can wrap the output without much effort):

Aardvarks, {ID}.
Bears.
   breeding, {ID}.
   feeding, {ID}.
   hunting, {ID}, {ID}.


Is there an easy way to do this?  Or is there a stylesheet out there that
already does this and I can just copy it into mine?  I've already looked at
the official docbook to html style sheet but the indexterm processing is
spread across a ton of little module files and I can't follow the logic at
all.  I just want something really simple.

Thanks --

Michele


Current Thread
Keywords