Subject: Re: [xsl] sum() applied to a product From: "Vasu Chakkera" <vasucv@xxxxxxxxxxx> Date: Wed, 30 Jun 2004 11:20:15 +0100 |
You could use a recursive template that does your stuff try this one.. <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="a"> <xsl:call-template name="add-b"> <xsl:with-param name="initial" select="0"/> <xsl:with-param name="counter" select="1"/> <xsl:with-param name="b-nodes" select="count(b)"/> </xsl:call-template> </xsl:template> <xsl:template name ="add-b"> <xsl:param name="initial"/> <xsl:param name="counter"/> <xsl:param name="b-nodes"/> <xsl:param name="value" select="(b[position()=$counter]/c)*(b[position()=$counter]/d)"/> <xsl:param name="sum" select="$initial+$value"/> <xsl:choose> <xsl:when test="$counter < $b-nodes"> <xsl:call-template name="add-b"> <xsl:with-param name="initial" select="$sum"/> <xsl:with-param name="counter" select="$counter+1"/> <xsl:with-param name="b-nodes" select="$b-nodes"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$sum"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> Hope this helps Vasu Ch.. ----- Original Message ----- From: "Brian Chrisman" <brian.chrisman@xxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Wednesday, June 30, 2004 12:36 AM Subject: [xsl] sum() applied to a product > Uggg... I had some sloppy cut-paste issue in my last post... this is what it should have been, with a real subject line. Sorry... > > ----------------------- > Okay.. I told someone I could do this in a simple xpath expression > > <?xml version="1.0"?> > <a> > <b> > <c>2</c> > <d>4</d> > </b> > <b> > <c>3</c> > <d>6</d> > </b> > </a> > > Where the xpath was to return (2*4) + (3*6) = 26 > I made several attempts with xpath's sum() function (using 1.0) and > couldn't get it. > I couldn't even come up with an expression that I thought might work.. > even though I tried several which I was certain would fail (which did). > > Any ideas? > > > > --+------------------------------------------------------------------ > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/ > or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx> > --+-- > >
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] sum() applied to a produc, Michael Kay | Thread | RE: [xsl] Testing for a following s, Wright, Steve |
RE: [xsl] XML style selected by bro, Andrew Welch | Date | RE: [xsl] XML style selected by bro, Joe Fawcett |
Month |