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

Re: Problem with Sum function

Subject: Re: Problem with Sum function
From: Meena Nanjundeswar <meenasargur@xxxxxxxxx>
Date: Mon, 22 Aug 2005 14:05:31 -0500
meena nanjundeswar
Well, the scenario is a little complicated. I have a stylesheet A with
an xml file A. Now, inside stylesheets A, I am displaying some
elements from an external XML file B, based on some values in
stylesheet A.

Eg:
XML A:

<root>
		<nodes>
			<node>
				<node--num>123</node-num>
				<child-nodes>
					<child-node-num>456</child-node-num>
	<child-node-num>789</child-node-num>


				</child-nodes>
			</node>
			</nodes>
			</root>

Now, my external xml file B has some additional values based on the
node-num and child-node-num from XML file A.

Eg: XML B would be like this:

<Bnode>
     <Bnode-num>123</Bnode-num>
             <Bchild-nodes1>
                      <Bchild-node1>
                                 <Bchild-node-num>456</Bchild-node-num>
                                  <Bchild-node-value>22</Bchild-node-value>
                      <Bchild-node1>
                        <Bchild-node1>
                                 <Bchild-node-num>789</Bchild-node-num>
                                  <Bchild-node-value>29</Bchild-node-value>
                      <Bchild-node1>

             </Bchildnodes1>

</Bnode>

Here is what I am doing in my stylesheet A. Now, I have some external
server calls made to match the node-num and child-node-num from XML A
with the correspondng values on XML B and display the
sum(Bchild-node-value).

	<xsl:template name="Bnode">
		<xsl:param name="mode"/>
		<xsl:for-each select="/root/nodes/node[child-nodes]">
			<xsl:variable name="node-num">
				<xsl:value-of select="node-num"/>
			</xsl:variable>
			<xsl:for-each select="./child-nodes/child-node-num">
				<xsl:variable name="child-node-num">
					<xsl:value-of select="."/>
				</xsl:variable>
				<xsl:apply-templates select="<!--This is servercall-->">
							<!--					</xsl:for-each>
		</xsl:for-each>
			</xsl:template>
	<xsl:template match="Bchild-node1">

		<xsl:value-of select="sum(Bchild-node-value)"/>

	</xsl:template>

Hope this is clear. Please let me know if there is any solution.

Thank you for all your help.

Meena

On 8/22/05, Mukul Gandhi <gandhi.mukul@xxxxxxxxx> wrote:
> Please try
>
> <xsl:template match="/node1">
>   <xsl:value-of select="sum(childnode1a/childnode11a/value)" />
> </xsl:template>
>
> Regards,
> Mukul
>
> On 8/22/05, Meena Nanjundeswar <meenasargur@xxxxxxxxx> wrote:
> > Hi:
> >
> > My xml file looks like this:
> >
> > <node1>
> >      <childnode1a>
> >             <childnode11a>
> >                     <value></value>
> >               </childnode11a>
> >       </childnode1a>
> > </node1>
> >
> > There can be any number of <childnode11a> elements containing <value>.
> > Now, I am trying to compute the sum(value). Instead of giving me a
> > total sum of all the rows, it display the values individually. I
> > believe we have to use recursion. Can anyone please help me with this
> > problem?
> >
> > Thanks
>
>


--
NorthWest Airlines
Office: 612-726-0793

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.