[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: "Christopher Giblin" <CGI@xxxxxxxxxxxxxx>
Date: Mon, 10 Dec 2001 11:44:07 +0100
chris giblin
As said, I am a newbie. As a result, your well-intended response is too
general to be useful. Thanks all the same.

I agree, simple stuff like this should be in an appendix to the spec for
all to see.
I am wasting mega cycles on this baisc point.

It seems to me that lack of useful examples seduces people onto
constructing proprietary XSLT extensions, weakening the language as a
standard.
I am interested in a 100% XLST 1.0 solution .

Cheers, chris




                                                                                                                                 
                    Trevor Nash                                                                                                  
                    <tcn@xxxxxxxxxxxxx>                To:     xsl-list@xxxxxxxxxxxxxxxxxxxxxx                                   
                    Sent by:                           cc:                                                                       
                    owner-xsl-list@xxxxxxxxxxxx        Subject:     Re:  newbie: xsl:key and summation of substrings        
                    rytech.com                                                                                                   
                                                                                                                                 
                                                                                                                                 
                    12/09/2001 07:35 PM                                                                                          
                    Please respond to xsl-list                                                                                   
                                                                                                                                 
                                                                                                                                 



>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".

The short answer is, you can't.  To use sum() the values have to be
present directly in the input, there is no way to preprocess them.

There are three longer answers:

1.  Use a recursive template.  This can be done with pure XSLT 1.0.
2.  Construct a temporary tree in a variable containing preprocessed
values, and then use sum() on that.  You will need to use the
node-set() extension function which most processors have.
3.  Do the transformation in two steps: step one is turn the document
into something sensible.

Be careful though - is it *always* MB or will you sometimes get KB or
GB or even TB?

>I can not influence the content of this source document.

I've lost count of the number of times I have seen this, most commonly
with grouping type questions.  Anybody got a theory as to why this
happens?  There must be thousands of person-hours being wasted.

Regards,
Trevor Nash
--
Traditional training & distance learning,
Consultancy by email

Melvaig Software Engineering Limited
voice:     +44 (0) 1445 771 271
email:     tcn@xxxxxxxxxxxxx

 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.