This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Re: how calculate sum(x*y)
- From: Andrey Solonchuk <solo at ibis dot odessa dot ua>
- To: Dimitre Novatchev <xsl-list at lists dot mulberrytech dot com>
- Date: Mon, 7 Oct 2002 14:06:50 +0300
- Subject: Re: [xsl] Re: how calculate sum(x*y)
- Organization: IBIS
- References: <20021007095436.34243.qmail@web14504.mail.yahoo.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hello Dimitre,
Monday, October 7, 2002, 12:54:36 PM, you wrote:
Thanks, for advise? but I try both variant and
explored that
<xsl:variable name="x">
<xsl:for-each select="//data">
<xsl:element name="ddd">
<xsl:value-of select="x * y"/>
</xsl:element>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="sum(xalan:nodeset($x)/ddd)"/>*
this variant vork mauch more faster than using FXSLT
may be I do something wrong, then correct me please
DN> --- Андрей Солончук <solo at ibis dot odessa dot ua> wrote:
>> Hello All,
>>
>> 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>
>>
>>
>> --
>> Best regards,
>> Andrey Solo mailto:solo@ibis.odessa.ua
DN> Hi Andrey,
DN> This is most easily done in a standard way by using the "foldl"
DN> template from the FXSL library.
DN> Given the following source xml:
DN> ------------------------------
DN> <root>
DN> <data>
DN> <x>2</x>
DN> <y>3</y>
DN> </data>
DN> <data>
DN> <x>5</x>
DN> <y>6</y>
DN> </data>
DN> <data>
DN> <x>4</x>
DN> <y>3</y>
DN> </data>
DN> </root>
DN> This transformation:
DN> -------------------
DN> <xsl:stylesheet version="1.0"
DN> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
DN> xmlns:foldl-func="foldl-func"
DN> exclude-result-prefixes="xsl foldl-func"
>>
DN> <xsl:import href="foldl.xsl"/>
DN> <foldl-func:foldl-func/>
DN> <xsl:variable name="vFoldlFun"
DN> select="document('')/*/foldl-func:*[1]"/>
DN> <xsl:output encoding="UTF-8" omit-xml-declaration="yes"/>
DN> <xsl:template match="/">
DN> <xsl:call-template name="foldl">
DN> <xsl:with-param name="pFunc" select="$vFoldlFun"/>
DN> <xsl:with-param name="pList" select="/*/*"/>
DN> <xsl:with-param name="pA0" select="0"/>
DN> </xsl:call-template>
DN> </xsl:template>
DN> <xsl:template match="foldl-func:*">
DN> <xsl:param name="arg1" select="0"/>
DN> <xsl:param name="arg2" select="/.."/>
DN> <xsl:value-of select="$arg1 + $arg2/x * $arg2/y"/>
DN> </xsl:template>
DN> </xsl:stylesheet>
DN> when applied on the above source xml document produces"
DN> 48
DN> This is a more efficient solution than first copying the products into
DN> a temporary node-set, then summing them (also possible with FXSL as:
DN> sum (zipWith (*) list1 list2)
DN> ), because it does not have to produce a big temporary node-set with
DN> all the products and then to have a second pass at this intermediate
DN> list.
DN> Hope this helped.
DN> =====
DN> Cheers,
DN> Dimitre Novatchev.
DN> http://fxsl.sourceforge.net/ -- the home of FXSL
DN> __________________________________________________
DN> Do you Yahoo!?
DN> Faith Hill - Exclusive Performances, Videos & More
DN> http://faith.yahoo.com
DN> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
--
Best regards,
Andrey mailto:solo@ibis.odessa.ua
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list