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

Re: Sum in conjunction with string splitting?

Subject: Re: Sum in conjunction with string splitting?
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Fri, 8 Sep 2006 10:53:06 -0700
Re:  Sum in conjunction with string splitting?
On 9/8/06, Steve <subsume@xxxxxxxxx> wrote:
Posted yesterday, but I isolated the problem significantly =)

The snippet below attempts to split the string 'mileage 6' into
[mileage] and [6] and then store it in $miles (for example).

I am trying to get the SUM of the resulting SPLIT of the nodes that
match 'mileage'.

I am close. Right now I only get one node, not the sum of all matches.

<xsl:variable name="miles">
       <xsl:call-template name="str-split-to-words">
               <xsl:with-param name="pStr"
select="msxsl:node-set($expenses[substring(expense,1,7)='mileage']/expense)"
/>
               <xsl:with-param name="pDelimiters" select="' '" />
                                     <!-- splitting expense at blank spaces -->
       </xsl:call-template>
</xsl:variable>
<xsl:value-of select="msxsl:node-set($miles)/*[2]" /><br />

====

$expenses example:

<Expenses>
   <expense>Mileage 6</expense>
   <expense>cheese</expense> (wouldn't match)
   <expense>Mileage 10</expense>
</Expenses>

====

Desired value of $miles: 16.

With FXSL2.0 one would simply write:


     sum(f:map(f:compose(f:decimal(),
                         f:flip(f:substring-after(),' ')
                         ),
               /*/*[contains(.,' ')]
               )
         )


Or simply use the f:transform-and-sum() function:


     f:transform-and-sum(f:flip(f:substring-after(),' '),
                         /*/*[contains(.,' ')]
                         )


In XSLT 1.0, one can use the "transform-and-sum" template of FXSL 1.x



-- Cheers, Dimitre Novatchev --------------------------------------- Truly great madness cannot be achieved without significant intelligence. --------------------------------------- To invent, you need a good imagination and a pile of junk




Thanks a bunch,


-Steve

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.