Solved

how to sum in xslt

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

911 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

18 Experts available now in Live!

Get 1:1 Help Now