This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: how calculate sum(x*y)


Hi,

> how calculate sum(x*y) ??
> 
> IF i try use sum() it say that need only node-list as argument....
> 
> I have xml
> <root>
>   <data>
>    <x>2</x>
>    <y>3</y>
>   </data>
>   <data>
>    <x>5</x>
>    <y>6</y>
>   </data>
>   .....
> <root>

Write a recursive template, that goes through all the data elements, summing the multiplication result to previous result sum, i.e.

template name=sum
  param name=node-set
  param name=sum

  if count($node-set') = 0
  then
    value-of select=$sum
  else
    call-template name=sum
      with-param name=node-set select=$node-set[not(position() = 1)]
      with-param name=sum select=$sum + $node-set[1]/x * $node-set[1]/y

Dimitri probably has some suitable function for the job, see [http://fxsl.sourceforge.net/].

Cheers,

Jarno - Grendel: Human Saviour

 

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]