Solved

how to sum in xslt

Posted on 2011-09-13
4
393 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
  • 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 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

809 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