addition with xsl fo

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cleary1981
    New Member
    • Jun 2008
    • 178

    #1

    addition with xsl fo

    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.
    Code:
    <!-- Nextpage: Quote -->
           		<fo:block break-before="page" space-before="2in" space-after="2in">
           		
             		<fo:block text-align="center" space-before="2cm">
            		Panels
            		</fo:block>
            		<fo:table space-before="1cm">
    				  <fo:table-body>
    				  <xsl:for-each select="quote/panels/panel">
    					    <fo:table-row>
    				      <fo:table-cell padding="6pt">
          				  <fo:block text-align="start"><xsl:value-of select="panel_name"/></fo:block>
         				 </fo:table-cell>
       				   <fo:table-cell padding="6pt">
        				    <fo:block text-align="end" space-after="2cm">£<xsl:value-of select="totalcost"/></fo:block>
     				     </fo:table-cell>
      				  </fo:table-row>
      				  </xsl:for-each>
      				  <fo:table-row>
      				  	<fo:table-cell>
      				  		<fo:block text-align="start" font-weight="bold" border-top="0.5pt solid red">Sub Total</fo:block>
      				  	</fo:table-cell>
      				  	<fo:table-cell>
      				  		<fo:block font-weight="bold" text-align="end" border-top="0.5pt solid red"></fo:block>
      				  	</fo:table-cell>
      				  	</fo:table-row>
      				  	</fo:table-body>
    				</fo:table>
    I need to add all the <xsl:value-of select="totalco st"/> values to get the total

    Thanks in advance
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by cleary1981
    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

    Comment

    • cleary1981
      New Member
      • Jun 2008
      • 178

      #3
      could you show me how?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Code:
        <xsl:value-of select="sum(quote/panels/panel/totalcost)"/>
        (didn't try it, but that's the syntax)

        Comment

        • cleary1981
          New Member
          • Jun 2008
          • 178

          #5
          Yeah that is exactly what I was looking for. I just add that into my code like so

          Code:
          <!-- Nextpage: Quote -->
                 		<fo:block break-before="page" space-before="2in" space-after="2in">
                 		
                   		<fo:block text-align="center" space-before="2cm">
                  		Panels
                  		</fo:block>
                  		<fo:table space-before="1cm">
          				  <fo:table-body>
          				  <xsl:for-each select="quote/panels/panel">
          					    <fo:table-row>
          				      <fo:table-cell padding="6pt">
                				  <fo:block text-align="start"><xsl:value-of select="panel_name"/></fo:block>
               				 </fo:table-cell>
             				   <fo:table-cell padding="6pt">
              				    <fo:block text-align="end" space-after="2cm">£<xsl:value-of select="totalcost"/></fo:block>
           				     </fo:table-cell>
            				  </fo:table-row>
            				  </xsl:for-each>
            				  <fo:table-row>
            				  	<fo:table-cell>
            				  		<fo:block text-align="start" font-weight="bold" border-top="0.5pt solid red">Sub Total</fo:block>
            				  	</fo:table-cell>
            				  	<fo:table-cell>
            				  		<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>
            				  	</fo:table-cell>
            				  	</fo:table-row>
            				  	</fo:table-body>
          				</fo:table>

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

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

            Comment

            Working...