Solved

how to sum in xslt

Posted on 2011-09-13
4
388 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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 …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now