The question applies to iteration over any sequence, except for the special case where the items in the sequence are siblings, in which case you can use preceding-sibling and following-sibling.
In general, use
<xsl:variable name="sequence" select="current-group()">
<xsl:for-each select="1 to count($sequence)">
<xsl:variable name="position" select="."/>
<xsl:variable name="currentItem" select="$sequence[$position]"/>
<xsl:variable name="previousItem" select="$sequence[$position - 1]"/>
Just remember that inside the for-each, the context item (.) is a number, not a node.
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference