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

RE: newbie: xsl:key and summation of substrings

Subject: RE: newbie: xsl:key and summation of substrings
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Sun, 9 Dec 2001 18:07:54 -0000
xsl key sum
Here are three ways to sum over a computed quantity:

* Create a result tree fragment containing nodes whose value is the computed
number, and use sum(xx:node-set($rtf//value)) to do the summation, where
xx:node-set() is your vendor's extension function for converting an RTF to a
node-set

* Use a recursive named template [this is the only standard XSLT 1.0
solution]

* Use the saxon extension function saxon:sum($nodes, saxon:expression(...))

Mike Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Christopher
> Giblin
> Sent: 09 December 2001 17:00
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  newbie: xsl:key and summation of substrings
>
>
> hi
>
> Despite reading the faqs, I am still banging my head on basic
> summation and
> would appreciate help.
>
> I have a repeating element that looks something like this:
>            <disk>
>      <freespace>1235 MB</freespace>
>            </disk>
>            <disk>
>      <freespace>40 MB</freespace>
>            </disk>
>            <disk>
>      <freespace>75  MB</freespace>
>            </disk>
>
>
> I want to sum the "freespace", but sum(//disk/freespace)
> won't work because
> freespace is not a number due to the trailing "MB".
> Of course, sum(substring-before(//disk/freespace, ' ')) does
> not work...
>
> So I thought the solution lies in  building an index of
> freespace values:
>
>      <xsl:key name="freespace" match="//disk" use
> ="substring-before(freespace,' ')"/>
>
>      <!-- output sum of freespace values: -->
>                 <total>
>          <xsl:value-of select="sum(key('freespace',.))"/>
>      </total>
>
> .. but it doesn't.
>
> I can not influence the content of this source document.
> How do I best sum over elements which need to be substring-parsed?
>
> I realize this is basic. I'm just not getting the examples in the faq.
>
> Thanks, chris
>
>
>
>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.