xsl-list
[Top] [All Lists]

Re: sum partial of the text

2005-10-05 13:40:50
On 10/5/05, piming(_dot_)kuo(_at_)worldspan(_dot_)com 
<piming(_dot_)kuo(_at_)worldspan(_dot_)com> wrote:

Is there any wavy to sum partial of the text? For example, I want to sum
all substring(data,7,4) from the following:

<segment>
     <data>XXXYYY1000</data>
     <data>XXXZZZ 100</data>
     <data>SSSYYY1200</data>
</segment>

The result will be:
1000 + 100 + 1200 = 2300


Using FXSL 2.0 (2.0 means simply "for XSLT 2.0"),  this one-liner
computes the wanted sum:

       sum(
           f:map(f:double(),
                 data/translate(.,
                                translate(., '0123456789', ''),''
                                )
                 )
          )

Unfortunately, the following is not permitted in XSLT 2.0 :

       sum(data/translate(., translate(., '0123456789', ''),'')/xs:double(.))


Cheers,
Dimitre Novatchev

--~------------------------------------------------------------------
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>