If you're not worried about performance then this is a doddle. I'll give the
schema-aware XSLT 2.0 version and leave you to retrofit it:
<xsl:template match="person/element(*, xs:decimal)
[sum(../../person/*[name()=name(current())]) != 0]">
<td><xsl:value-of select="."/></td>
</xsl:template>
That's a template that matches all children of <person> whose schema type is
xs:decimal. You need another version (that does nothing) for the case where
the total is zero.
(There's another 2.0 dependency buried in here, by the way: current() is not
allowed in 1.0 match patterns.)
However, this calculates the total amount of overtime once for each record,
which is O(n^2). To do better than this, calculate the totals first, and
pass a list of the names of excluded elements (in 1.0 you could represent
this list as a space-separated string) as a parameter to each of the
templates.
Michael Kay
-----Original Message-----
From: Richard Huxtable [mailto:huxtabler(_at_)rpo(_dot_)co(_dot_)uk]
Sent: 18 May 2004 13:10
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Show a column only if the total is not zero
The costs on a project look like this.
<person>
<name>Adam</name>
<fees>134.25</fees>
<overtime>0.00</overtime>
<travel>39.25</travel>
</person>
<person>
<name>Brian</name>
<fees>172.50</fees>
<overtime>0.00</overtime>
<travel>52.75</travel>
</person>
<person>
<name>Chris</name>
<fees>103.75</fees>
<overtime>0.00</overtime>
<travel>0.00</travel>
</person>
I would like the report on the project to look like this.
name fees travel
Adam 134.25 39.25
Brian 172.50 52.75
Chris 103.75 0.00
Total 410.50 92.00
There was no overtime on this project so I don't want it
shown. I should
be most grateful for any suggestions on the best way to show
the columns
where the total is not zero. (In practice I have more than 3 types of
cost.)
Many thanks.
--+------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--