xsl-list
[Top] [All Lists]

Recursion

2003-11-25 21:27:53
I'm having a little trouble with recursion and could use some guidance
please.

My basic XML is this:

<Root>
        <Child1>
                <Dates>
                        <StartDate>..here is a date/time</StartDate>
                        <EndDate>..here is a date/time</EndDate>
                </Dates>
        </Child1>
        <Child2>
                ....same type of children
        </Child2>
                ...
                ...
                ...


I would like to basically get the duration between each StartDate and
EndDate, and get a total sum of those durations.

Here is my current code:

...
...
<xsl:call-template name="totalHours">
        <xsl:with-param select="Dates/DateSpan/StartDate"
name="startDate"/>
        <xsl:with-param select="Dates/DateSpan/EndDate" name="endDate"/>
</xsl:call-template> ... ...



<xsl:template name="totalHours">
        <xsl:param name="startDate"/>
        <xsl:param name="endDate"/>
        <xsl:variable name="duration">
                <xsl:call-template name="date:difference">
                        <xsl:with-param name="start"
select="$startDate"/>
                        <xsl:with-param name="end" select="$endDate"/>
                </xsl:call-template>
        </xsl:variable>
    <xsl:choose>
      <xsl:when test="$duration">
        <xsl:variable name="recursive_result">
          <xsl:call-template name="totalHours">
            <xsl:with-param name="start" select="$startDate[position()
&gt;  1]"/>
                        <xsl:with-param name="end"
select="$endDate[position() &gt; 1]"/>
          </xsl:call-template>
                </xsl:variable>
        <xsl:value-of select="date:add-duration(0 +
$recursive_result)"/>
                </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="0"/>
      </xsl:otherwise>
  </xsl:choose>
</xsl:template>

I'm currently getting an error saying that 'startDate should contain a
node-set'.

I appreciate any help.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>