This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Summary Totals by Type
- To: Ron Grimes <rgrimes at sinclairoil dot com>
- Subject: Re: Summary Totals by Type
- From: Jeni Tennison <jeni at friday dot u-net dot com>
- Date: Fri, 28 Jul 2000 19:25:29 +0100
- Cc: "XSL List (E-mail)" <XSL-List at mulberrytech dot com>
- Reply-To: xsl-list at mulberrytech dot com
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@epistemics.co.uk
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list