Link to home
Start Free TrialLog in
Avatar of nkk1712
nkk1712

asked on

how to sum in xslt

i want use sum function.  Here i want perform the sum which in bold,
To help you i have given like this.
[ In this for loop i want sum each xsl:value-of ]

<xsl:template name="getContentiousAmount">
      <xsl:param name="partyReference" as="xs:string"/>
            <xsl:for-each select="../../../../../../facilityPosition/positionInfo/position[positionTypeCode/upper-case(code) = 'FACILITYENDOFPERIODCONTENTIOUSAMOUNT']">
             <xsl:chose>
                   <xsl:when test="../position[positionTypeCode/upper-case(code) eq 'FACILITYENDOFPERIODUNPAIDAMOUNT']">
                         <xsl:value-of select="0"/>                   </xsl:when>
                   <xsl:otherwise>
                         <xsl:value-of select="../../drawdownPosition/positionInfo/position
                  [positionTypeCode/upper-case(code) eq 'DRAWDOWNENDOFPERIODUNPAIDAMOUNT'][partyReference/@href eq $partyReference]
                  //positionAmounts/node()[name() eq  'positionAmount']/amount"/>
                  </xsl:otherwise>
             </xsl:chose>                  
            </xsl:for-each>
      </xsl:template>
CPMPROD-D-CPM-LOA-20110617-0000-.XML
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

just wrap a sum around it
<xsl:value-of select="sum(../../drawdownPosition/positionInfo/position
                  [positionTypeCode/upper-case(code) eq 'DRAWDOWNENDOFPERIODUNPAIDAMOUNT'][partyReference/@href eq $partyReference]
                  //positionAmounts/node()[name() eq  'positionAmount']/amount)"/>  
Avatar of nkk1712
nkk1712

ASKER

please check its a for loop and i want to have sum for the both conditions
Example
the result of the above may give like this....

     0
     250
     350
     0
     500

now i want the sum as  [0 +  250 + 350 + 0 + 500] = 1100.
Acutally its and condition. i am not able to get the proper result when use xpath as
folllows

sum(../../../../../../../facilityPosition[positionInfo[position
                  [positionTypeCode/upper-case(code) eq 'FACILITYENDOFPERIODCONTENTIOUSAMOUNT'][partyReference/@href eq $partyReference]]
                  [position[positionTypeCode/upper-case(code) !='FACILITYENDOFPERIODUNPAIDAMOUNT']]]
                  /drawdownPosition/positionInfo/position[positionTypeCode/upper-case(code) eq 'DRAWDOWNENDOFPERIODUNPAIDAMOUNT']
                  [partyReference/@href eq $partyReference]//positionAmounts/node()[name() eq $elementName]/ag:getPositionAmount(amount, currency, $tag_Currency))
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the sum() by the way is outside the loop