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

RE: Recursion Help with Summing Durations

Subject: RE: Recursion Help with Summing Durations
From: "Sal Mangano" <smangano@xxxxxxxxxx>
Date: Wed, 1 May 2002 22:44:07 -0400
recursion help
Worked for me in both Saxon and Xalan 2.3.1

My input:

<timecard>
    <shift>
       <duration>P13M</duration>
    </shift>
    <shift>
       <duration>P43M</duration>
    </shift>
</timecard>

The Stylesheet:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:date="http://exslt.org/dates-and-times"
extension-element-prefixes="date">
  
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  
  <xsl:template match="timecard">
    <xsl:call-template name="total-durations">
      <xsl:with-param name="durations" select="shift/duration"/> 
    </xsl:call-template>
  </xsl:template>
  
  <xsl:template name="total-durations">
    <xsl:param name="durations"/>
    <xsl:choose>
      <xsl:when test="$durations">
        <xsl:variable name="first" select="$durations[1]"/>
        <xsl:variable name="rest">
          <xsl:call-template name="total-durations">
            <xsl:with-param name="durations"
select="$durations[position()!=1]"/>
          </xsl:call-template>
        </xsl:variable>
        <xsl:call-template name="date:add-duration">
          <xsl:with-param name="duration1" select="$first"/>
          <xsl:with-param name="duration2" select="$rest"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>P0M</xsl:otherwise>
    </xsl:choose>
  </xsl:template>

...
I used Jeni's XSLT impl of add-duration here...

</xsl:stylesheet>

The ouput:

P4Y8M



> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-
> list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Seth Ladd
> Sent: Monday, April 29, 2002 2:28 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Recursion Help with Summing Durations
> 
> Hello,
> 
> I am trying to use the EXSLT template add-duration.  I have a node-set
> of durations that I'd like to sum together.  My named template is not
> working, and I was hoping someone could give me some hints or tips on
> where to go to make this recursion work properly.
> 
> My environment:
> 
> Java 1.3.1
> Xalan2
> Cocoon 2.0.2
> 
> I've tested that I'm getting the correct node-set by using count().
> I've also hard-coded some values into add-duration to make sure it
> works.
> 
> I've been scanning documentation all day, and coming up empty.  I
might
> be getting tripped up with the difference between node-sets and RTFs,
> but that's where my XSLT gets fuzzy.  Any tips or suggestions would be
> greatly appreciated!
> 
> Thanks so much,
> Seth
> 
> My template:
> 
>     <xsl:template name="total-durations">
>         <xsl:param name="durations"/>
> 
>         <xsl:choose>
>             <xsl:when test="$durations">
>                 <xsl:variable name="first" select="$durations[1]"/>
>                 <xsl:variable name="rest">
>                     <xsl:call-template name="total-durations">
>                         <xsl:with-param name="durations"
>                                 select="$durations[position()!=1]"/>
>                     </xsl:call-template>
>                 </xsl:variable>
> 
>                 <xsl:call-template name="date:add-duration">
>                     <xsl:with-param name="duration1" select="$first"/>
>                     <xsl:with-param name="duration2" select="$rest"/>
>                 </xsl:call-template>
> 
>             </xsl:when>
>             <xsl:otherwise>P0M</xsl:otherwise>
>         </xsl:choose>
> 
>     </xsl:template>
> 
> I call it with this (while I am in the timecard element):
> 
> <xsl:call-template name="total-durations">
>     <xsl:with-param name="durations" select="shift/duration"/>
> </xsl:call-template>
> 
> And my original document looks like:
> 
> <timecard>
>     <shift>
>        <duration>P13M</duration>
>     </shift>
>     <shift>
>        <duration>P43M</duration>
>     </shift>
> </timecard>
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 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.