Hi Greg,
is seems like you generate the the document "a2" twice. The second time
you generate it you overwrite the contents of the first run.
<xsl:template match="CCC">
<exsl:document href="{../../@id}" method="text">
<xsl:for-each select='../..//CCC'>
<xsl:value-of select="."/>
</xsl:for-each>
</exsl:document>
</xsl:template>
That should do the job. I'd rewrite the templates so you don't have to
step up two levels each time:
<xsl:template match="/">
<xsl:apply-templates select="AAA"/>
</xsl:template>
<xsl:template match="AAA">
<exsl:document href="{(_at_)id}" method="text">
<xsl:for-each select='descendant::CCC'>
<xsl:value-of select="."/>
</xsl:for-each>
</exsl:document>
</xsl:template>
Regards,
Wolfgang