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 August 20th, 2004, 05:13 AM
Registered User
 
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default sum() when ...

hello,
I want to sum() all 'text' nodes in 'position' when the 'number' in 'position' is '1'.

the problem I have is that he summs all 'text' notes when there is only one <nr>1</nr>

my xslt:
<xsl:variable name="sum" select="sum(//../../../../../../text)"></xsl:variable>
<xsl:variable name="art" select="//../../../../../../nr"></xsl:variable>
<xsl:variable name="length10" select="..."></xsl:variable>

<xsl:choose>
    <xsl:when test="$nr='1'">
    <xsl:value-of select="concat(substring($null, 0,$length10),substring($betrag,1,10))"></xsl:value-of>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="substring($null, 1, 10)"/>
    </xsl:otherwise>
</xsl:choose>


here the structure of my xml

<list>
    <list2>
        <data>
        ...
        <send>
        ...
        <senddata>
        ...
        <positions>
               <position>
                    <nr>1</nr>
                    <text>12345</text>
               </position>
        </positions>
        <positions>
               <position>
                    <nr>2</nr>
                    <text>54321</text>
               </position>
        </positions>
        <positions>
               <position>
                    <nr>1</nr>
                    <text>54321</text>
               </position>
        </positions>
    ...
...

thanks for helping!


 
Old August 20th, 2004, 06:22 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Not sure I follow but would something like:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <xsl:value-of select="sum(//text[../nr = 1])" />
  </xsl:template>
</xsl:stylesheet>
be what you need?

--

Joe (MVP - xml)





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.