Subject: Re: [xsl] Addition problem From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Tue, 11 Feb 2003 14:10:08 +0000 |
Hi Sandeep, > Here is my XML Doc and XSL DOC , All I want to do is to add the size > of all the Documents. I know with 'Sum' Can be used as straight > function , but I want to achieve the same with my logic as I have to > I have to do increment/decrements and other manipulations based on > conditions. If you don't want to use sum(), you need to use recursion. Create a template that takes a set of llnode elements and a current total as parameters. If any llnodes are passed to the template, then call the template recursively, adding the value for the first llnode to the current total, and passing the node set without that first llnode element. If the aren't any llnodes then the current total is your final answer. Here is the recursive template: <xsl:template name="sumSizes"> <xsl:param name="llnodes" select="/mynode/llnode" /> <xsl:param name="total" select="0" /> <xsl:choose> <xsl:when test="$llnodes"> <xsl:variable name="value" select="$llnodes[1]/@size" /> <xsl:call-template name="sumSizes"> <xsl:with-param name="llnodes" select="$llnodes[position() > 1]" /> <xsl:with-param name="total" select="$total + $value" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$total" /> </xsl:otherwise> </xsl:choose> </xsl:template> You can generate the value of the $value variable in any way that you like; here it's just getting the value of the 'size' attribute but you can set it however you like. > Also it would be great if you can guide me as to how to include > javascript in xsl document. It depends on what you mean by including javascript in the XSLT stylesheet. Do you want to define extension functions that you can use in XPath expressions in your stylesheet? If so, then how you do it depends on your processor; if you're using MSXML, you can use the <msxsl:script> element. If you just want to add some Javascript into the HTML output that you're creating, then include it in the stylesheet just as you would any other text. The XSLT processor won't recognise it as Javascript. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Addition problem, Sandeep Jain | Thread | [xsl] XML Rendering in Netscape/Moz, Rick Taylor |
RE: [xsl] Debugging XSL with XML Sp, Marty McKeever | Date | RE: [xsl] Debugging XSL with XML Sp, dave beattie |
Month |