I was wondering if it's possible to sort an XPATH location. Here
is basically what I'm trying to solve:

The XML document is of the following format:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="export-common.xsl"?>
<items>
<item>
<first>foo</first>
<second>bar</second>
</item>
<item>
<first>web</first>
<second>smith</second>
</item>
<item>
<first>Reykjavik</first>
<second>Iceland</second>
</item>
</items>

I have an XSL stylesheet that displays the <first> and <second>
elements in an HTML table, sorted in ascending order on the
<first> element:

<xsl:sort select="first" data-type="text" order="ascending" />

Now I would like to compare the 1st letter of each <first> element
with the previous entry, to display a header if the letter is
different, like a glossary:

A
acrobat a circus performer; software by adobe
anteater an animal that eats ants

B
border to delineate the transition from one zone to another

C
caravan etc...

So here is the XPATH expression:

<xsl:value-of select="substring(current()/preceding-sibling::item[position()=1]/first, 1, 1)" />

The problem is that the XPATH expression will reference the first letter of the previous <first> entry in the XML document, not the
sorted display.

How can the XPATH location be changed to reference the sorted
output?