[xsl] Re: sum of the evaluated values

Subject: [xsl] Re: sum of the evaluated values
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Thu, 22 Nov 2001 02:31:47 -0800 (PST)
> 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"
exclude-result-prefixes="xsl func-transform"
   <xsl:import href="transform-and-sum.xsl"/>

   <xsl:output method="text"/>

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


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

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

gives the following result:


Hope this helped.

Dimitre Novatchev.

Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.

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

Current Thread