Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 3rd, 2011, 04:21 PM
Registered User
 
Join Date: Jan 2011
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default Sum variables

Hi

I have a xsl with this:

<xsl:variable name="if" select="count($unit//if)"/>
<xsl:variable name="for" select="count($unit//for)"/>
<xsl:variable name="case" select="count($unit//switch/block/case)"/>
<xsl:variable name="while" select="count($unit//while)"/>

I need sum all the $if, $for, $case, $while. How can I do this?

Any ideas?
 
Old February 3rd, 2011, 06:12 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

How about adding them up?

<xsl:variable name="sum" select="$if + $for + $case + $while"/>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
mejias (February 3rd, 2011)
 
Old February 3rd, 2011, 06:42 PM
Registered User
 
Join Date: Jan 2011
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by samjudson View Post
How about adding them up?

<xsl:variable name="sum" select="$if + $for + $case + $while"/>
I am going crazy!!!
 
Old February 4th, 2011, 07:18 AM
Registered User
 
Join Date: Jan 2011
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Post Total usgin variables

Hi.

I have a xsl like this:

<xsl:variable name="totalizador" select="0"/>
<xsl:template match="/">
<xsl:for-each select="unit">
<xsl:variable name="unit" select="."/>
<xsl:variable name="cant_funciones" select="count(function)"/>
<xsl:variable name="cant_clases" select="count(class)"/>[INDENT][/INDENT]<xsl:variable name="totalizador" select="$totalizador + $cant_funciones"/>

How to calculate the total using variables?

Any ideas?
 
Old February 4th, 2011, 07:29 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You can't update variables in XSLT, so you need to work out how to calculate your total outside of the for-each loop, something like this:

Code:
<xsl:variable name="totalizador" select="count(unit/function) + count(unit/class)"/>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: Running Sum (or Cumulative Sum) timdasa VB Databases Basics 1 August 22nd, 2006 03:12 PM
Sum Jonas Access VBA 1 August 4th, 2006 12:41 PM
sum utarian Access 2 March 28th, 2005 09:42 PM
sum ibelta Access 2 February 15th, 2005 08:53 AM
SUM or What bertlf Pro VB Databases 2 November 29th, 2003 02:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.