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

Re: Calculating Column Total

Subject: Re: Calculating Column Total
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 29 Mar 2010 02:20:38 +0100
Re:  Calculating Column Total
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[@complete='N'])"/>
</xsl;template>

David

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.