[xsl] Trying to sort node set while tagging specific nodes in it

Subject: [xsl] Trying to sort node set while tagging specific nodes in it
From: Stan <sgd@xxxxxxxxxxxx>
Date: Wed, 27 Jul 2005 11:20:25 -0400
I want to transform the following...

<root>
   <rec>
      <name>z</name>
      <year>2004</name>
   </rec>
   <rec>
      <name>z</name>
      <year>2005</year>
   </rec>
   <rec>
      <name>a</name>
      <year>2002</year>
   </rec>
   <rec>
      <name>a</name>
      <year>2003</year>
   </rec>
</root>

...to...


<root> <rec> <name tag="latest">a</name> <year>2003</year> </rec> <rec> <name>a</name> <year>2002</year> </rec> <rec> <name tag="latest">z</name> <year>2005</year> </rec> <rec> <name>z</name> <year>2004</name> </rec> </root>

In other words, sort by <name> ascending and then by <year> descending
while tagging the most recent of each name.

The sorting is easy, but tagging the most recent is proving difficult
for me. I thought to use the preceding axis to test the preceding name
and if it is different than the current name put in the tag attribute,
but as I understand it, the precding axis  applies to document order,
not sort order. Is there some better way to do this?

Thanks,
Stan Dyck

Current Thread