Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old June 22nd, 2006, 10:35 AM
Authorized User
Join Date: Jun 2006
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Getting percentages with math functions

I am needing to get percentages from an xml file into another xml file.

Here is a snippet of the in file(there will be hundreds of the <pavement_x0020_Conditions> nodes in the real file):

and here is a snippet of how I need it to look:

Basically I need to know how to pull all the areas for all types (e.g., AC, PCC) add them, and figure a percentage for each. I actually know how to pull each type's area and add it with the Sum() function (I think), it's the percentage that I am having trouble with.

Thanks in advance.
  #2 (permalink)  
Old June 22nd, 2006, 11:47 AM
Authorized User
Join Date: May 2006
Location: Chico, CA, USA.
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts

I think what you want is something like:

(count(//surface[.='AC']) div count(//surface)) * 100


(sum(//pavement_x0020_Conditions/Area[../Surface = 'AC']) div sum(//pavement_x0020_Conditions/Area)) * 100

Also, since the grand total remains throughout constant, you could declare a variable for it:

<xsl:variable name='GrandTotal' select='sum(//pavement_x0020_Conditions/Area)' />


Similar Threads
Thread Thread Starter Forum Replies Last Post
Math Functions on dynamic data jroxit Classic ASP Basics 3 January 23rd, 2007 12:07 PM
Crystal Reports: Displaying percentages of total q Goalie35 Crystal Reports 0 December 21st, 2006 05:51 PM
Graphics Math Functions vb certified Pro VB.NET 2002/2003 2 January 1st, 2006 11:06 AM
Math functions-Please help! jroxit ASP.NET 2.0 Basics 5 December 28th, 2005 12:21 PM
Why are my math functions not being included? jkeen BOOK Beginning Linux Programming, 3rd Edition 4 October 22nd, 2004 05:29 AM

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