XSLT For-each Loop for sum value of particular field

I have below XSLT which gives the values from Bankaccount table and BankCheque table in AX when provide as an input XSLT for Positive pay.

I need to get sum value of Amount field and Count value of the ChequeNumber field out side of the for each loop.

Kindly suggest any idea or logic to get it i am struggling for long time to get this.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="www.w3.org/.../Transform"
xmlns:exslt="http://exslt.org/common" extension-element-prefixes="exslt"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl s0 s1 xslthelper" xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02"
xmlns:xsi="www.w3.org/.../XMLSchema-instance" xmlns:xslthelper="schemas.microsoft.com/.../xslthelper"
xmlns:s0="schemas.microsoft.com/.../sharedtypes" xmlns:s1="schemas.microsoft.com/.../BankPositivePay"
>

<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
     <xsl:template match="/">
     <xsl:apply-templates select="//s1:BankPositivePay"></xsl:apply-templates>
      </xsl:template>
      <xsl:template match="//s1:BankPositivePay">
    <Document>
             <xsl:for-each select="s1:BankAccountTable">
                  <xsl:if test="count(child::s1:BankChequeTable) >0">
                         <xsl:variable name="AccountNum" select="s1:AccountNum"/>
                         <xsl:variable name="RegistrationNum"select="s1:RegistrationNum"/>
                    <xsl:for-each select="s1:BankChequeTable">
                         <xsl:value-of select='string("I")'/>
                         <xsl:value-of select="$AccountNum"/>
                         <xsl:value-of select="$RegistrationNum"/>
                         <xsl:value-of select='s1:ChequeNum/text()'/>
                         <xsl:value-of select='s1:TransDate/text()'/>
                         <xsl:value-of select='s1:AmountCur/text()'/>
                      </xsl:for-each>
                   </xsl:if>
             </xsl:for-each>
        </Document>
</xsl:template>

 

Thanks

Hari

Related
Recommended