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 4th, 2010, 10:24 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default Sum of attibutes

Hi, how to a get a total numerical value of attributes from siblings? I need to get the total value of all the colspec/@colwidth that are a child of tgroup. Here is some code.

xml sample
Code:
<tgroup cols="2" colsep="1" rowsep="1">
              <colspec colnum="1" colname="col1" colwidth="12pi" colsep="1" rowsep="1"/>
              <colspec colnum="2" colname="col2" colwidth="12pi" colsep="1" rowsep="1"/>
               <thead>
......
XSLT Template

Code:
<xsl:template match="colspec">
    <xsl:variable name="total">
        <xsl:choose>
            <xsl:when test="contains(../colspec/@colwidth, 'pi')">
                <xsl:value-of select="sum(number(substring-before(../colspec/@colwidth, 'pi')))"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="number(0)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <!--to do-->
</xsl:template>
Thanks for the help
 
Old March 4th, 2010, 10:45 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This one is easy in XSLT 2.0, hard in 1.0.

In 2.0

sum(for $x in ../colspec/@colwidth return number(substring-before($x, 'pi')))

For some of the approaches possible in XSLT 1.0, see http://www.dpawson.co.uk/xsl/sect2/N...tml#d6610e1271
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
bonekrusher (March 4th, 2010)
 
Old March 4th, 2010, 12:22 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Perfect. Thank you very much





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to sum in for-each Gjella XSLT 1 October 2nd, 2006 08:48 AM
Help: Running Sum (or Cumulative Sum) timdasa VB Databases Basics 1 August 22nd, 2006 03:12 PM
sum utarian Access 2 March 28th, 2005 09:42 PM
need sum help! jbik BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 December 20th, 2004 05:27 PM
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.