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

RE: Is there another way to do this?

Subject: RE: Is there another way to do this?
From: Jarno.Elovirta@xxxxxxxxx
Date: Wed, 3 Mar 2004 12:38:19 +0200
xsl node number
Hi,

> I use this call when I have matched="saledetails":
> 
> <xsl:call-template name="grandtotal">
>    <xsl:with-param name="nodenumber" select="1"/>
>    <xsl:with-param name="grandtotal" select="0"/>
> </xsl:call-template>
> 
> To this template:
> 
> <xsl:template name="grandtotal">
>    <xsl:param name="nodenumber"/>
>    <xsl:param name="grandtotal"/>
>    <xsl:choose>
>       <xsl:when test="not(item[$nodenumber])">
>          <xsl:value-of select="format-number($grandtotal, '#0.00')"/>
>       </xsl:when>
>       <xsl:otherwise>
>          <xsl:call-template name="grandtotal">
>             <xsl:with-param name="nodenumber" select="$nodenumber+1"/>
>             <xsl:with-param name="grandtotal"
> select="$grandtotal+(item[$nodenumber]/units *
> item[$nodenumber]/unit.price)"/>
>          </xsl:call-template>
>       </xsl:otherwise>
>    </xsl:choose>
> </xsl:template>
> 
> This works but I'm just wondering is there a simpler method 
> for doing this?

Not really. You could use e.g. FXSL so you wouldn't have to write the recursive template; implementation-wise, I'd probably use e.g.

  <xsl:apply-templates select="item[1]" mode="sum"/>

in saledetails element with 

  <xsl:template match="item" mode="sum">
    <xsl:param name="grandtotal" select="0" />
    <xsl:choose>
      <xsl:when test="not(following-sibling::item)">
        <xsl:value-of select="format-number($grandtotal+(units * unit.price), '#0.00')"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="following-sibling::item[1]" mode="sum">
          <xsl:with-param name="grandtotal" select="$grandtotal+(units * unit.price)"/>
        </xsl:apply-templates>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

but that's just a matter of taste and doesn't make the template any more simple, really.

Cheers,

Jarno

 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.