9 Replies Latest reply: Feb 21, 2008 6:54 AM by remc0

# don't show 0 when the sum of a group is null

Hello all,

When the following in a group:
<?sum(current-group()/_saw_8_[.!=’’])?>

It returns a 0 when all values are null.
But 0 means smaller then 0,5 and null means it is not there
Now my question is: how can I sum the values and make a different between 0 and null?

Best regards,
Remco
• ###### 1. Re: don't show 0 when the sum of a group is null
put the value in a variable do and if statement. if sum_value != "0" and sum_value != ""
• ###### 2. Re: don't show 0 when the sum of a group is null
Ok, and how can I do that?
(sorry for the question, but as we say in holland: I don't have eaten any chees of variables)
• ###### 3. Re: don't show 0 when the sum of a group is null
To declare a variable named 'xxx' use the following syntax
<?xdoxslt:set_variable(\$_XDOCTX, 'xxx', 0)?>
This will declare the variable 'xxx' and assign it a value 0

To change the value of the variable use
<?xdoxslt:set_variable(\$_XDOCTX, 'xxx', 1)?>

To retrieve the value to the variable use
<?xdoxslt:get_variable(\$_XDOCTX, 'xxx') ?>

The value of the variable can be compared with some value as follows
<?if: xdoxslt:get_variable(\$_XDOCTX, 'xxx') =0?>
• ###### 4. Re: don't show 0 when the sum of a group is null
Hey Remco

<?xdoxslt:ifelse(sum(AMOUNT[.!=""])=0,'',sum(AMOUNT[.!=""]))?>

So if the sum = 0 ie all null then dont show anything otherwise sow the amount. The only problem will be if you have '0' values
Tim
• ###### 5. Re: don't show 0 when the sum of a group is null
Hi Remco,

Are you trying to summate a list of values that could contain nulls?

If so then using <?sum(ELEMENTS)?> will not work and probably give you NaN errors, instead, try using <?xslt:sum(ELEMENTS)?>, this should ignore null elements and return the correct result.

I hope this helps.

Regards,

Cj
• ###### 6. Re: don't show 0 when the sum of a group is null
Hi Chris and Brown,

I am trying to summate a list of values indeed, but the list is in a group.
So if I want to summate the list I must use: <?sum(current-group()/ELEMENT)?>.

But both of your replies will help me out.
@Tim: Sometimes the list is as following: null, null, null, 0 --> if that happens I want to see a 0 if the list is null, null, null, null then I want to see nothing
@Chris: I don't get any NaN errors when I use <?sum(current-group()/ELEMENT)?>
But when I am using <?xslt:sum(current-group()/ELEMENT)?> I will get a error. Only when I choose tools -> validate it says there are no errors, but when I request a preview it returns an error without any details.

Best regards,

Remco
• ###### 7. Re: don't show 0 when the sum of a group is null
Could you count the number of elements, compare it to the count of the number of elements that are null, if they are the same then output null otherwise output the sum.

Something like ( haven't tested it...)

<?xdoxslt:ifelse(count(AMOUNT[.!=""])=count(AMOUNT),'',sum(AMOUNT[.!=""]))?>

hope it helps
Graham
• ###### 8. Re: don't show 0 when the sum of a group is null
Thanks! It looks like this is what I want!

Best regards,
Remc0
• ###### 9. Re: don't show 0 when the sum of a group is null
Thanks again Graham,

Untill today we hadn't any time to test what you said.. but to count the elements was a good idea! This is the exact syntax we are using now:
<?xdoxslt:ifelse(count(current-group()/_saw_2_)=0,'',sum(current-group()/_saw_2_))?>

And this works fine!