Subject: Re: [xsl] Re: how calculate sum(x*y) From: Andrey Solonchuk <solo@xxxxxxxxxxxxxx> Date: Mon, 7 Oct 2002 14:06:50 +0300 |
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@xxxxxxxxxxxxxx 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@xxxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Re: how calculate sum(x*y), Dimitre Novatchev | Thread | [xsl] sum function used for values , Jackson, Michael |
RE: [xsl] sum function used for val, TSchutzerWeissmann | Date | RE: [xsl] xsl:number counting "cous, Michael Kay |
Month |