469,356 Members | 2,013 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

addition with xsl fo

178 100+
Hi,

Im a little out of my depth using xsl fo here. I have a table of items and each has a price in the second row of the table. I need to display a total at the bottom of the row. My problem is that I can't work out how to perform addition in xsl fo.

Here's my xsl file where I have created the table.
Expand|Select|Wrap|Line Numbers
  1. <!-- Nextpage: Quote -->
  2.                <fo:block break-before="page" space-before="2in" space-after="2in">
  3.  
  4.                  <fo:block text-align="center" space-before="2cm">
  5.                 Panels
  6.                 </fo:block>
  7.                 <fo:table space-before="1cm">
  8.                   <fo:table-body>
  9.                   <xsl:for-each select="quote/panels/panel">
  10.                         <fo:table-row>
  11.                       <fo:table-cell padding="6pt">
  12.                         <fo:block text-align="start"><xsl:value-of select="panel_name"/></fo:block>
  13.                       </fo:table-cell>
  14.                       <fo:table-cell padding="6pt">
  15.                         <fo:block text-align="end" space-after="2cm"><xsl:value-of select="totalcost"/></fo:block>
  16.                       </fo:table-cell>
  17.                     </fo:table-row>
  18.                     </xsl:for-each>
  19.                     <fo:table-row>
  20.                         <fo:table-cell>
  21.                             <fo:block text-align="start" font-weight="bold" border-top="0.5pt solid red">Sub Total</fo:block>
  22.                         </fo:table-cell>
  23.                         <fo:table-cell>
  24.                             <fo:block font-weight="bold" text-align="end" border-top="0.5pt solid red"></fo:block>
  25.                         </fo:table-cell>
  26.                         </fo:table-row>
  27.                         </fo:table-body>
  28.                 </fo:table>
I need to add all the <xsl:value-of select="totalcost"/> values to get the total

Thanks in advance
Dec 17 '08 #1
5 4859
Dormilich
8,652 Expert Mod 8TB
@cleary1981
XSL-FO is for layouting. use XSL for the computation (esp. the XPath functions (e.g. sum()))) .

regards
Dec 17 '08 #2
cleary1981
178 100+
could you show me how?
Dec 17 '08 #3
Dormilich
8,652 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. <xsl:value-of select="sum(quote/panels/panel/totalcost)"/>
(didn't try it, but that's the syntax)
Dec 17 '08 #4
cleary1981
178 100+
Yeah that is exactly what I was looking for. I just add that into my code like so

Expand|Select|Wrap|Line Numbers
  1. <!-- Nextpage: Quote -->
  2.                <fo:block break-before="page" space-before="2in" space-after="2in">
  3.  
  4.                  <fo:block text-align="center" space-before="2cm">
  5.                 Panels
  6.                 </fo:block>
  7.                 <fo:table space-before="1cm">
  8.                   <fo:table-body>
  9.                   <xsl:for-each select="quote/panels/panel">
  10.                         <fo:table-row>
  11.                       <fo:table-cell padding="6pt">
  12.                         <fo:block text-align="start"><xsl:value-of select="panel_name"/></fo:block>
  13.                       </fo:table-cell>
  14.                       <fo:table-cell padding="6pt">
  15.                         <fo:block text-align="end" space-after="2cm"><xsl:value-of select="totalcost"/></fo:block>
  16.                       </fo:table-cell>
  17.                     </fo:table-row>
  18.                     </xsl:for-each>
  19.                     <fo:table-row>
  20.                         <fo:table-cell>
  21.                             <fo:block text-align="start" font-weight="bold" border-top="0.5pt solid red">Sub Total</fo:block>
  22.                         </fo:table-cell>
  23.                         <fo:table-cell>
  24.                             <fo:block font-weight="bold" text-align="end" border-top="0.5pt solid red"><xsl:value-of select="sum(quote/panels/panel/totalcost)"/></fo:block>
  25.                         </fo:table-cell>
  26.                         </fo:table-row>
  27.                         </fo:table-body>
  28.                 </fo:table>
Dec 17 '08 #5
Dormilich
8,652 Expert Mod 8TB
bear in mind that the XPath I used is a guess (though I hope a good one).
Dec 17 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Mark Dickinson | last post: by
3 posts views Thread by Jay | last post: by
2 posts views Thread by akickdoe22 | last post: by
24 posts views Thread by Alex Vinokur | last post: by
5 posts views Thread by Paul | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.