Just for fun, until you post your input sample and stylesheet building that text output, this stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="result" name="result">
<xsl:param name="pString" select="."/>
<xsl:variable name="vAfter" select="substring-after($pString, 'AAA+')"/>
<xsl:choose>
<xsl:when test="$vAfter!=''">
<xsl:variable name="vId"
select="substring-before($vAfter, '+')"/>
<xsl:variable name="vEnd"
select='concat("XXX+number_of_records+",$vId,"'
")'/>
<xsl:variable name="vInto"
select="substring-before($vAfter,$vEnd)"/>
<xsl:value-of
select='concat(substring-before($pString,"AAA+"),
"AAA+",
$vInto,
"XXX+",
string-length(translate($vInto,
translate($vInto,
"
",
""),
"")) + 1,
"+",$vId,"'
")'/>
<xsl:call-template name="result">
<xsl:with-param name="pString"
select="substring-after($vAfter,$vEnd)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$pString"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
With this input:
<result>
HDR+aaa:bbb'
AAA+78901234567890+String1:String2'
BBB+123+String'
CCC+321:1212'
DDD+112211'
DDD+121122'
XXX+number_of_records+78901234567890'
AAA+1234567890+String1:String2'
BBB+123+String'
CCC+321:1212'
DDD+1212:2121'
BBB+123+String'
BBB+122+String'
CCC+String'
XXX+number_of_records+1234567890'
</result>
Output:
HDR+aaa:bbb'
AAA+78901234567890+String1:String2'
BBB+123+String'
CCC+321:1212'
DDD+112211'
DDD+121122'
XXX+6+78901234567890'
AAA+1234567890+String1:String2'
BBB+123+String'
CCC+321:1212'
DDD+1212:2121'
BBB+123+String'
BBB+122+String'
CCC+String'
XXX+8+1234567890'