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 March 6th, 2012, 07:27 AM
Authorized User
 
Join Date: Feb 2008
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default summing nos in string

Hello all,

I have strings like

string:1
string:2
string:31

etc

I want to sum of the numbers in it

using xslt
__________________
tq98
 
Old March 6th, 2012, 07:42 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Well with XSLT/XPath 2.0 you can do e.g.
Code:
sum(for $s in ('string:1', 'string:2', 'string:31') return xs:integer(substring-after($s, ':')))
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old March 6th, 2012, 09:27 AM
Authorized User
 
Join Date: Feb 2008
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks for the reply,
but I need the solution for xslt 1.0 version
__________________
tq98
 
Old March 6th, 2012, 09:33 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

2 ways.

In pure XSLT 1.0 you could write a recursive template, that takes a set of nodes, parses the first one, and then passes the rest into the template again, returning the first node value, plus whatever is returned by the recursive call.

Or you could parse the nodes once, then feed the resulting nodeset into a variable, which is then summed. To do this you would have to use something like exsl:node-set().
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old March 6th, 2012, 09:38 AM
Authorized User
 
Join Date: Feb 2008
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default

can you please provide me some sample code in 1.0
__________________
tq98
 
Old March 6th, 2012, 09:52 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Consider to post a sample of the XML you have as the input first.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
Totaling/Summing string values bsparker XSLT 1 July 20th, 2011 05:17 PM
Summing up errror zary Beginning PHP 2 March 13th, 2010 10:40 PM
Increment of Alphabetic nos(A to Z) monika.vasvani ASP.NET 2.0 Basics 1 May 9th, 2008 02:07 AM
Summing up in a loop Tschuri XSLT 0 May 3rd, 2005 07:16 AM
Summing and Exporting imhotep666 Excel VBA 3 August 18th, 2004 11:25 PM





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