sum() function in XSL

Posted on 2003-03-26
Medium Priority
Last Modified: 2012-06-21
Hi all,

I am tryig to find the sum of "MoneyAccountValue". But I donot get anykind of o/p nor i get anykind of error.

Here is the XSL code...

Total : <xsl:variable name="total" select="sum(Accounts/BrokerageAccount/@MoneyAccountValue)" />

and the XML code is...........

<BrokerageAccount Name="Account1" Number="1234" Registration="CMA Direct" MoneyAccountValue="1000" />
<BrokerageAccount Name="Account2" Number="1235" Registration="IRA" MoneyAccountValue="1000" />


I would appreciate if someone can find the reason....

Question by:kalpana_kk
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 14

Accepted Solution

avner earned 100 total points
ID: 8215705
Have you tried to ouput the value of the variable $total ?

I tried, and it works fine :

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
     <xsl:output method="html" indent="yes" encoding="iso-8859-1" />
     <xsl:template match="/">
     <xsl:variable name="total" select="sum(Accounts/BrokerageAccount/@MoneyAccountValue)" />
     <xsl:value-of select="$total"/>

Assisted Solution

foxyshadis earned 100 total points
ID: 8228816
Depending on your XSLT implementation, you may have to use

<xsl:variable name="total" select="sum(Accounts/BrokerageAccount/@MoneyAccountValue[1])" />

As some (like Xalan) seem to require the position on attribute values. *shrug* Just a guess.

Expert Comment

ID: 8646418
Atleast Xalan-C does not require [1].

Featured Post

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question