Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to sum in xslt

Posted on 2011-09-13
4
Medium Priority
?
400 Views
Last Modified: 2013-11-18
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
0
Comment
Question by:nkk1712
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 36529986
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)"/>  
0
 

Author Comment

by:nkk1712
ID: 36533936
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))
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 36534567
"sum(../../../../../../facilityPosition[positionInfo/position[positionTypeCode/upper-case(code) = 'FACILITYENDOFPERIODCONTENTIOUSAMOUNT']]/drawdownPosition/positionInfo/position
                  [positionTypeCode/upper-case(code) eq 'DRAWDOWNENDOFPERIODUNPAIDAMOUNT'][partyReference/@href eq $partyReference]
                  //positionAmounts/node()[name() eq  'positionAmount']/amount)"

will work (since the second condition returns zero, so you don't need to add them)

note that your XML has a namespace,
so facilityPosition does not exist, except in the namespace
since this seems to do something for you,
- you either have stripped out the namespace prior to your XSLT
- you are using default x-path namespace in XSLT2

if none of teh above is true, you need to add prefixes everywhere for that namespace

and...
usually there is little reason for not replacing ../../../../../../../facilityPosition
with ancestor::facilityPosition
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 36534568
the sum() by the way is outside the loop
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question