xsl-list
[Top] [All Lists]

RE: [xsl] XSLT 1.0 newbie: sum of selected elements

2006-12-11 07:51:03
If your document were an XML document, then this would do what you asked:

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

Your document is not an XML document because the attribute values are not 
enclosed in quotes. NO PROCESSOR, Xalan or otherwise will (or certainly should 
not) accept the document you showed.

-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     Kirov Plamen <pkirov(_at_)globul(_dot_)bg>
Sent:     Mon, 11 Dec 2006 15:08:43 +0200
To:       <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject:  [xsl] XSLT 1.0 newbie: sum of selected elements

Hello,

I'm trying to sum the selected values from xml, using xsl with Xalan:

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>


I want to sum @due only for @id=2 or 3

XSL:

<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". Is't possible, for this
example, elements with @id 2 or 3 to be selected first and after to be
summarized @due and/or @init?

BR
Plamen

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>
  • RE: [xsl] XSLT 1.0 newbie: sum of selected elements, cknell <=