473,410 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

xslt count

I would like to sum up several numbers using xsl.
I have tried <xsl:value-of select="count(//TotalScenarios)" /but that
only returns the number of times that the tag "TotalScenarios" appears,
and does not sum the actual value contained in the tag.

Here is my xml.

<ScenarioSummary>
<LastRunDate>Aug 29, 2006 3:56:44 PM</LastRunDate>
<Scenario>
<Area>FacilityCharges</Area>
<TotalScenarios>3</TotalScenarios>
<SuccessfulScenarios>2</SuccessfulScenarios>
<FailedScenarios>1</FailedScenarios>
<ErrorScenarios>0</ErrorScenarios>
</Scenario>
<Scenario>
<Area>GasSales</Area>
<TotalScenarios>4</TotalScenarios>
<SuccessfulScenarios>0</SuccessfulScenarios>
<FailedScenarios>0</FailedScenarios>
<ErrorScenarios>4</ErrorScenarios>
</Scenario>
<ScenarioSummary>

I would like to be able to sum up the totalScenarios,
SuccessfulScenarios, etc, and expect the results below.

Total scenarios should be: 7
Total success: 2
Total failed: 1
Total error: 4

Aug 30 '06 #1
2 1458
http://www.w3.org/TR/1999/REC-xpath-...6#function-sum

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Aug 30 '06 #2

Hi Wlaver,
Comment: your XML is not well formated. The first tag is not well
closed!!!!!!!!!

i will solve your problem by sending the code and result:
good lock

XSL code:
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/">
<Total>
<Totalscenarios>
<xsl:value-of
select="sum(ScenarioSummary/Scenario/TotalScenarios)"/>
</Totalscenarios>
<Totalsuccess>
<xsl:value-of
select="sum(ScenarioSummary/Scenario/SuccessfulScenarios)"/>
</Totalsuccess>
<Totalfailed>
<xsl:value-of
select="sum(ScenarioSummary/Scenario/FailedScenarios)"/>
</Totalfailed>
<Totalerror>
<xsl:value-of
select="sum(ScenarioSummary/Scenario/ErrorScenarios)"/>
</Totalerror>
</Total>
</xsl:template>
<xsl:stylesheet>

Result Totals:

<?xml version='1.0' ?>
<Total>
<Totalscenarios>7</Totalscenarios>
<Totalsuccess>2</Totalsuccess>
<Totalfailed>1</Totalfailed>
<Totalerror>4</Totalerror>
</Total>

wl****@gmail.com wrote:
I would like to sum up several numbers using xsl.
I have tried <xsl:value-of select="count(//TotalScenarios)" /but that
only returns the number of times that the tag "TotalScenarios" appears,
and does not sum the actual value contained in the tag.

Here is my xml.

<ScenarioSummary>
<LastRunDate>Aug 29, 2006 3:56:44 PM</LastRunDate>
<Scenario>
<Area>FacilityCharges</Area>
<TotalScenarios>3</TotalScenarios>
<SuccessfulScenarios>2</SuccessfulScenarios>
<FailedScenarios>1</FailedScenarios>
<ErrorScenarios>0</ErrorScenarios>
</Scenario>
<Scenario>
<Area>GasSales</Area>
<TotalScenarios>4</TotalScenarios>
<SuccessfulScenarios>0</SuccessfulScenarios>
<FailedScenarios>0</FailedScenarios>
<ErrorScenarios>4</ErrorScenarios>
</Scenario>
<ScenarioSummary>

I would like to be able to sum up the totalScenarios,
SuccessfulScenarios, etc, and expect the results below.

Total scenarios should be: 7
Total success: 2
Total failed: 1
Total error: 4
wl****@gmail.com wrote:
I would like to sum up several numbers using xsl.
I have tried <xsl:value-of select="count(//TotalScenarios)" /but that
only returns the number of times that the tag "TotalScenarios" appears,
and does not sum the actual value contained in the tag.

Here is my xml.

<ScenarioSummary>
<LastRunDate>Aug 29, 2006 3:56:44 PM</LastRunDate>
<Scenario>
<Area>FacilityCharges</Area>
<TotalScenarios>3</TotalScenarios>
<SuccessfulScenarios>2</SuccessfulScenarios>
<FailedScenarios>1</FailedScenarios>
<ErrorScenarios>0</ErrorScenarios>
</Scenario>
<Scenario>
<Area>GasSales</Area>
<TotalScenarios>4</TotalScenarios>
<SuccessfulScenarios>0</SuccessfulScenarios>
<FailedScenarios>0</FailedScenarios>
<ErrorScenarios>4</ErrorScenarios>
</Scenario>
<ScenarioSummary>

I would like to be able to sum up the totalScenarios,
SuccessfulScenarios, etc, and expect the results below.

Total scenarios should be: 7
Total success: 2
Total failed: 1
Total error: 4
Aug 31 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Graham | last post by:
Hi, I am having trouble getting XSL to count the members of a group. What I am trying to do is group by <objectid.Contactid> and count the number of <activityid>'s for each <objectid.contactid>....
5
by: inquirydog | last post by:
Hi- Does anyone know a way to compare whether two nodes contain the same information in xslt (the name, attributes, and all content recursivly should be the same. I am interested in the case...
2
by: Sylvia | last post by:
Hi, I'm trying to render a XML structure to HTML using XSLT. My XML describe the header of a table with a complex and not linear structure. The first row of the header table always contains the...
4
by: Chris Kettenbach | last post by:
Hi Peter, I get error when processing the stylesheet. It errors here. <xsl:for-each select="registration)=1]"> specifically: Expression does not return a DOM node. registration)=1]<--
1
by: cameron | last post by:
I am attempting to pass in an XmlDocument as a parameter to a transform: from my sample ASPX page: string BaseDir = "/cameron/Play/ComplexParam/"; XmlDocument XSL = new XmlDocument();...
1
by: jrwarwick | last post by:
Hello, I believe I have uncovered a bug in the .Net XSLT engine to do with 'for' loops in XSLT. Here are the steps to reproduce it: -Create A new webform project. -Add the xml file...
0
by: DAnne | last post by:
Hi, I'm very new to xslt and this is my first time posting to a Forum so please forgive me if I transgress any protocols. I have to do a tally report. This report is divided up into sections....
0
by: DAnne | last post by:
I'm trying to do a simple count function in xslt and it's turning out to be extremely painful. I have a report that brings back a set of responses for each question per section in an Audit. I...
4
by: J | last post by:
I've spent most of the day on this, and I just can't seem to find a solution, please help me! :) I'm recieving XML that I can't modify that looks like: <?xml version="1.0"?> <Doc> <Page>...
4
by: shaun roe | last post by:
I should like to count the frequency of strings embedded in a longer string, space separated. Specifically, I have: <phiModule> 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 8 5 5 5 6 6 6 7 7 7 7 7 7 7 7...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.