[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Summary Totals by Type

Subject: Re: Summary Totals by Type
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 28 Jul 2000 19:25:29 +0100
xslt sum condition
Ron,

>So, how can I change this function to give me YTD totals for just transtype
>= "Claim"?
>
><xsl:script><![CDATA[
>    function ytdClaims(node) {
>      total = 0;
>      claims = node.selectNodes("/flexact/fsatrans/transamount");
>      for (c = claims.nextNode(); c; c = claims.nextNode())
>	  total += c.nodeTypedValue;
>        return formatNumber(total, "$###,##0.00");
>    }
>]]></xsl:script>

At the moment, the XPath you're using translates as:

a transamount element that is a child of
  a fsatrans element that is a child of
    a flexact element that is the document element

You want only those transamount elements that are a child of a fsatrans
element that has a transtype child whose value is 'Claim'.  Conditions like
this are known as predicates, and you put them in square brackets after the
node that you're placing the condition on.  In your case "a fsatrans
element whose a transtype child whose value is 'Claim'" translates to the
step:

  fsatrans[transtype = 'Claim']

So if you use the XPath:

  /flexact/fsatrans[transtype = 'Claim']/transamount

you will get only the 'Claim'-type transamounts.

As an aside, if you're using this within a stylesheet, you could possibly
use the built-in sum() function from XPath and the format-number() function
from XSLT rather than a new function:

  format-number(sum(/flexact/fsatrans[transtype = 'Claim']/transamount), 
                "$###,##0.00")

I hope that helps,

Jeni

Dr Jeni Tennison
Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE
tel: 0115 906 1301 * fax: 0115 906 1304 * email: jeni.tennison@xxxxxxxxxxxxxxxx


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.