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

Re: Addition problem

Subject: Re: Addition problem
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 11 Feb 2003 14:10:08 +0000
addition problem
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

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.