Connecting Tech Pros Worldwide Help | Site Map

addition with xsl fo

Familiar Sight
 
Join Date: Jun 2008
Posts: 164
#1: Dec 17 '08
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
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#2: Dec 17 '08

re: addition with xsl fo


Quote:

Originally Posted by cleary1981 View Post

My problem is that I can't work out how to perform addition in xsl fo.

XSL-FO is for layouting. use XSL for the computation (esp. the XPath functions (e.g. sum()))) .

regards
Familiar Sight
 
Join Date: Jun 2008
Posts: 164
#3: Dec 17 '08

re: addition with xsl fo


could you show me how?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#4: Dec 17 '08

re: addition with xsl fo


Expand|Select|Wrap|Line Numbers
  1. <xsl:value-of select="sum(quote/panels/panel/totalcost)"/>
(didn't try it, but that's the syntax)
Familiar Sight
 
Join Date: Jun 2008
Posts: 164
#5: Dec 17 '08

re: addition with xsl fo


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>
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#6: Dec 17 '08

re: addition with xsl fo


bear in mind that the XPath I used is a guess (though I hope a good one).
Reply


Similar XML bytes