xsl-list
[Top] [All Lists]

Re: [xsl] Calculating Column Total

2010-03-28 20:20:53
On 29/03/2010 01:57, Shashank Jain wrote:

All,

I am stuck in calculating total of another column.

My XML is



<data>

<event_template sp_doctypes="Research Note, Prior Stock Report, Stock Report">

       <event  complete='Y' />

       <event  complete='N' />

   </event_template>

   <event_template sp_doctypes=" Prior Stock Report, Stock Report">

       <event  complete='Y' />

       <event  complete='N' />

       <event  complete='N' />

       <event  complete='Y' />

</event_template>
</data>


This is the xsl I am using

<xsl:template match="/">
         <xsl:value-of select="fns:sumMissing_template(event)"/>
  </xsl:template>

<xsl:function name="fns:sumMissing_template">
   <xsl:param name="everyEvent" as="element()*"/>
     <xsl:variable name="Num_Docs_Missing">
          <xsl:choose>
                 <xsl:when test="@complete='Y'">
                     <xsl:value-of select="0"/>
                 </xsl:when>
                 <xsl:otherwise>
                      <xsl:value-of select="1"/>
                 </xsl:otherwise>
          </xsl:choose>
     </xsl:variable>
<xsl:sequence select="sum(for $x in $everyEvent return($Num_Docs_Missing))"/>
</xsl:function>

I am trying to calculate the sum of $Num_Docs_Missing for all the events.
Please let me know where I am doing wrong.

Thanks
Shashank

if you use xsl;variable without an as attribute you generate a document node containing a text node, and simlarly if you use value-of you always generate a text node. If you want a numeric valued function it is far better to use numbers rather than text nodes.

in
> <xsl:template match="/">
>          <xsl:value-of select="fns:sumMissing_template(event)"/>

you pass your function the sequence of event children of the document node, but the only child of that node has name data, so this is the empty sequence.

It appears that you just want

 <xsl:template match="/">
         <xsl:value-of select="count(//event[(_at_)complete='N'])"/>
</xsl;template>

David



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--