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

Re: sum of the evaluated values

Subject: Re: sum of the evaluated values
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Thu, 22 Nov 2001 02:31:47 -0800 (PST)
select sum time type
> i have xml:
>   <event type="1" time="3:00">
>   <event type="0" time="2:00">
>   <event type="1" time="4:00">
>   <event type="1" time="5:00">
> and i need sum of the minutes: number(substring-before(@time,':'))
> only where @type=1.
> 
> How it can  be done?

Yet aother application for the transform-and-sum template 
(see http://sources.redhat.com/ml/xsl-list/2001-11/msg00831.html )

Here's how you could use it:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:func-transform="f:func-transform"
exclude-result-prefixes="xsl func-transform"
>
   <xsl:import href="transform-and-sum.xsl"/>

   <xsl:output method="text"/>
   
   <func-transform:func-transform/>

    <xsl:template match="/">
      <xsl:call-template name="transform-and-sum">
        <xsl:with-param name="pFuncTransform" 
                        select="document('')/*/func-transform:*[1]"/>
        <xsl:with-param name="pList" select="/*/*/@time"/>
      </xsl:call-template>
    </xsl:template>
    
    <xsl:template match="func-transform:*">
      <xsl:param name="arg" select="0"/>
      <xsl:value-of select="substring-before($arg, ':')"/>
    </xsl:template>

</xsl:stylesheet>

This when applied on your xml source (corrected to be weel-formed):

<events>
  <event type="1" time="3:00"/>
  <event type="0" time="2:00"/>
  <event type="1" time="4:00"/>
  <event type="1" time="5:00"/>
</events>

gives the following result:

14


Hope this helped.

Cheers,
Dimitre Novatchev.



__________________________________________________
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1

 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.