XSLT SUM  IF example

Posted on 2011-05-02
Last Modified: 2013-11-11

Thank you for taking the time to look at my question.

Essentially I have the following XSL:

and what I want to do is if account=16 and trpaymentdate > 20091231 and trpaymentdate is <=20100131 sum of all tr_toagency and sum of all tr_to_client and then sum these two figures together.

Could someone please help with how the XSLT sheet would look?  Once I see how you go about that I can then fill in what I need to.

Many thank you's in advance.
Question by:mavmanau
    LVL 18

    Accepted Solution

    Please test the following template, I guess it's that you need
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="">
    	<xsl:template match="/">
    		<xsl:variable name="scope" select="/clientdemo/transaction[account = 16 and tr_payment_date &gt; 20091231 and tr_payment_date &lt;= 20100131]"/>
    		<xsl:value-of select="sum($scope/tr_to_agency) + sum($scope/tr_to_client)"/>

    Open in new window


    Author Comment

    many thank you's I think I can work out most of what I need from there except for one more quick question that I forgot to include as part of original.  Say I am feeding in a value for clientrowid.  When the page first loads, this is of course blank, but if the user clicks on a row above this particular section and selects a particular clientrowid that is then fed into the XSLT page, how would I then make it choose to only do the ones with that particular ClientROWid...say for example it is 2??

    Author Comment

    that works perfect though, the first part you have given me.

    Author Closing Comment

    Thank you!! very appreciative, very quickly done too!!
    LVL 18

    Expert Comment

    You welcome. So, did you figure out how to feed an input id value?

    Author Comment

    i think so...I am trying at the moment!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
    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 …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

    759 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

    9 Experts available now in Live!

    Get 1:1 Help Now