If you want to combine all the nodes following <A>, but come before the next <A>, I think you can use something like this:
<xsl:template match="A">
<xsl:copy>
<xsl:variable name="start" select="count(preceding-sibling::*) + 1" />
<xsl:variable name="stop">
<xsl:choose>
<xsl:when test="following-sibling::A">
<xsl:value-of select="count(following-sibling::A[1]/preceding-sibling::*) + 1" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="count(../*) + 1" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:attribute name="range">
<xsl:value-of select="concat($start + 1, '-', $stop - 1)" />
</xsl:attribute>
<xsl:for-each select="../*[position() > $start and position() < $stop]">
<xsl:copy-of select="." />
</xsl:for-each>
</xsl:copy>
</xsl:template>
To enter:
<root>
<A />
<ab />
<ac />
<A />
<ab />
<ac />
</root>
I get (I left the "range" attribute to make the calculations visible):
<A range="2-3">
<ab />
<ac />
</A>
<A range="5-6">
<ab />
<ac />
</A>