Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] Totals for conditional sums ?maybe?

From: "Michael Kay" <mike@------------>
To:
Date: 12/3/2005 5:12:00 PM
> What I am trying to do is total the ORDD_TLNA for the base 
> years when 
> //AwardFullData/AwardItemizedLine[count(./periodLinePeriodNumb
> er)&lt;1] and then later total ORDD_TLNA for the option years 
> when 
> //AwardFullData/AwardItemizedLine[count(./periodLinePeriodNumb
> er)&gt;0]">
> 
> I have tried so many iterations I have forgotten them all but 
> I think the closest I have gotten is this:
> 
> <xsl:variable name="TEST" 
> select="//AwardFullData/AwardItemizedLine[count(./periodLinePe
> riodNumber)&lt;1]"/>
> <xsl:variable name="ADDME" 
> select="//AwardFullData/AwardItemizedLine/transactionAmount"/>
> ...

For some reason you've made this much more complicated than it is. Just
select the nodes you want to total and apply the sum() function:

 
sum(//AwardFullData/AwardItemizedLine[count(./periodLinePeriodNumber)&lt;1]/
transactionAmount"/>

I'm assuming here that transactionAmount does actually hold a numeric value.
You haven't shown your source document, but there's a possible hint later in
your question that suggests trasactionAmount might hold a currency sign. If
that's the case then in 2.0 you can do

sum(//AwardFullData/AwardItemizedLine[count(./periodLinePeriodNumber)&lt;1]/
transactionAmount/
       number(translate(.,'$',''))"/>
> 
> <xsl:value-of select="sum($ADDME[$TEST])"/>

There are several reasons this is wrong. Firstly, any expression of the form
$ADDME[XXX] is going to select a subset of the nodes in $ADDME. These are
AwardItemizedLine nodes, whereas you want to sum transactionAmount nodes.
Secondly, $TEST is taken as true if
//AwardFullData/AwardItemizedLine/transactionAmount selects any nodes, and
as false if it doesn't; the value doesn't depend in any way on the
AwardAtomizedLine node in question.
> 
> 
> Not even sure if the above was correct I tried to strip the 
> formatting of the data which includes $ and , (I have no 
> control over the data source).

At this point I think we need to see what the data looks like.

A general comment: you're trying to do this by trial and error, which isn't
a very good way of learning the language. The stylesheets you're working
with aren't very well written, so learning from them isn't a good idea
either. Take some time to read a good XSLT book.

Michael Kay
http://www.saxonica.com/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent