When the first letter of the title changes from
a -> b-> c,
That's a pretty accurate description of the use case for which XSLT 2.0
group-adjacent is designed:
<xsl:for-each-group select="ROW/COL/DATA" group-adjacent="substring(.,1,1)">
<a>...</a>
<xsl:for-each select="current-group()">
In general, grouping in XSLT 1.0 is much harder. For this problem you have a
choice of (a) grouping entirely by value, ignoring the fact that the groups
are already adjacent, using the Muenchian grouping technique (see
http://www.jenitennison.com/xslt/grouping), or (b) writing a recursive
template to process the list of entries, starting a new level of recursion
whenever you hit a title that starts with a different letter from the
previous one.
However, it might be that a simpler solution will work here because you
don't actually need to wrap all the titles beginning with the same letter in
a parent element, you only need to output the <a> when the letter changes.
You can do this with something like
<xsl:template match="DATA">
<xsl:if test="substring(.,1,1) != substring(preceding::DATA[1],1,1)">
<a>...</a>
</xsl:if>
rest of logic
</xsl:template>
With luck, someone will show you a worked solution.
Michael Kay