[xsl] sorting and preceding-sibling - only print *first* in sorted list??

Subject: [xsl] sorting and preceding-sibling - only print *first* in sorted list??
From: "Hardy Merrill" <HMerrill@xxxxxxxxxxxxxxxx>
Date: Tue, 12 Oct 2004 09:55:29 -0400
I know this topic has been covered ad-nauseum, but even after reading
the faq and googling, I can't quite "get" what I need to do to make this
work.

Here is a sample xml doc:

<legislators>
    <legislator>
        <legislator_id>1</legislator_id> 
        <legislator_active>1</legislator_active> 
        <legislator_active_date>20020101000000</legislator_active_date>

        <district_id>046</district_id> 
        <district_type>A</district_type> 
        <district_no>001</district_no>  
        <full_name>Doe, John J.</full_name> 
    </legislator>
    <legislator>
        <legislator_id>21</legislator_id> 
        <legislator_active>0</legislator_active> 
        <legislator_active_date>19960101000000</legislator_active_date>

        <district_id>046</district_id> 
        <district_type>A</district_type> 
        <district_no>001</district_no>  
        <full_name>Smith, Jane</full_name> 
    </legislator>
    <legislator>
        <legislator_id>95</legislator_id> 
        <legislator_active>1</legislator_active> 
        <legislator_active_date>20020101000000</legislator_active_date>

        <district_id>034</district_id> 
        <district_type>A</district_type> 
        <district_no>002</district_no>  
        <full_name>Jones, Daniel</full_name> 
    </legislator>
</legislators>

I want my xsl style sheet to produce html with the records in this
order:

District    Legislator
----------   ---------------
001 A       Doe, John J.
001 A       Smith, Jane
002 A       Jones, Daniel

Notice that legislators for the same district are listed together. 
What I
can't seem to figure out is how to ONLY print the district info for the
*first* district in the sorted list.  So I *want* that listing to look
like this:

District    Legislator
----------   ---------------
001 A       Doe, John J.
                  Smith, Jane
002 A       Jones, Daniel

Currently I have this for-each loop and sort's:

<xsl:for-each select="$section_legislators">
      <xsl:sort select="district_type" />
      <xsl:sort select="district_no" data-type="number" />
      <xsl:sort select="legislator_active_date" 
                      data-type="number"
                      order="descending" />

I was trying to use "preceding-sibling" to figure out if the previous
sibling ***in sorted order*** had the same district, but I've now
figured out after reading on the subject that "preceding-sibling" does
not operate on the sorted tree - instead it operates on the original
tree that is in "document" order.

I'd like to use the best/most efficient method to solve this problem -
the muncheon technique using keys if possible.  Can I do that, and if
so, how?

TIA.

Hardy Merrill
New York State Division of Housing & Community Renewal

Current Thread