[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSLT 1.0 newbie: sum of selected elements

Subject: Re: XSLT 1.0 newbie: sum of selected elements
From: Florent Georges <darkman_spam@xxxxxxxx>
Date: Mon, 11 Dec 2006 14:55:57 +0100 (CET)
sum elements xsl
Kirov Plamen wrote:

  Hi

> <xsl:value-of select="sum(..//element[type/@id = 2 or type/@id =
> 3]/amount/@due)"/>

> If I want to sum by more than 5 different Id's or/and for
> more amount values(@due, @init...), this method of sorting
> values is unusual - a lot of repeated "or" clauses for
> every "select".

  You can use something like the following:

    (drkm)[139] ~/xslt/tests$ cat kirov.xsl
    <xsl:transform
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:my="my:kirov.xsl"
        version="1.0">

      <xsl:output method="text"/>

      <my:ids>
        <elem id="2"/>
        <elem id="3"/>
      </my:ids>

      <xsl:variable name="ids" select="
          document('')/*/my:ids/elem/@id"/>

      <xsl:template match="root">
        <xsl:value-of select="
            sum(element[type/@id = $ids]/amount/@due)"/>
      </xsl:template>

    </xsl:transform>

    (drkm)[140] ~/xslt/tests$ cat kirov.xml
    <root>
      <element>
        <type id="1" des="a"/>
        <amount due="10.12" init="0.25"/>
      </element>
      <element>
        <type id="2" des="a"/>
        <amount due="1.82" init="1.00"/>
      </element>
      <element>
        <type id="1" des="a"/>
        <amount due="-12.00" init="0.00"/>
      </element>
      <element>
        <type id="3" des="a"/>
        <amount due="50.00" init="120.35"/>
      </element>
    </root>

    (drkm)[141] ~/xslt/tests$ saxon kirov.xml kirov.xsl
    Warning: at xsl:transform on line 4 of kirov.xsl:
      Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor
    51.82

    (drkm)[142] ~/xslt/tests$ xsltproc kirov.xsl kirov.xml
    51.82

    (drkm)[143] ~/xslt/tests$

  Regards,

--drkm


























	

	
		
___________________________________________________________________________ 
Dicouvrez une nouvelle fagon d'obtenir des riponses ` toutes vos questions ! 
Profitez des connaissances, des opinions et des expiriences des internautes sur Yahoo! Questions/Riponses 
http://fr.answers.yahoo.com

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.