You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Josh Campbell <jo...@zype.co.nz> on 2002/03/25 05:59:11 UTC

Adding columns using XSL

Hi all

I've got a column of numbers being pulled out of XML that I want to 
total at the bottom of the page using the XSL.
I don't know how many rows of figures will be generated so need 
something that can just take all the values in a column and add them up

The logic of this has defied me and I was hoping someone would be able 
to provide a solution.

Thanks in advance,
Josh

ZYPE - Graphical Interface Design
Phone: 03 3862094
Mobile: 021 400 472
Web: www.zype.co.nz




Re: Adding columns using XSL

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Josh Campbell wrote:
> I've got a column of numbers being pulled out of XML that I want to 
> total at the bottom of the page using the XSL.
> I don't know how many rows of figures will be generated so need 
> something that can just take all the values in a column and add them up
Check out the sum() function:
  http://www.w3.org/TR/xpath#section-Number-Functions
If your XML is something like this
  <records>
    <record>
      <name>foo</name><price>99.0</price>
    <record>
    </record>
      <name>bar</name><price>100.0</price>
    </record>
  </records>
use it like
   <xsl:template match="records">
     <xsl:text>Total: </xsl:text>
     <xsl:value-of select="sum(record/price)"/>
   </xsl:template>
If your problem is more complicated, ask on the XSL list
(http://www.mulberrytech.com/xsl/xsl-list/), because you
have an XSLT problem rather than a FOP problem. Provide
some more details: a relevant snippet of your XML, and how
to derive the "total" you are after. If your computation
involves something like price*quantity per record, look
into the list archives first.

J.Pietschmann