[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 09:54:54 +0100
Re:  Calculating Column Total
On 29/03/2010 05:55, Shashank Jain wrote:

Thanks David for this.


But I want to pass the value of the variable which follow certain conditions. In my previous post I made the conditions too simple (sorry about that).
Also thanks for correcting me that I was matching my template to the document node.
I am trying to run


<xsl:template match="/"> <xsl:value-of select="fns:sumMissing_template(event_template)"/>
the only child of / is the elementwith name data, so you are passing an empty sequence to your function. I think you intended to pass a sequence of event elements which would be "fns:sumMissing_template(//event)


</xsl:template>



<xsl:function name="fns:sumMissing_template">
<xsl:param name="eventTemplate " as="element()*"/>
   <xsl:variable name="Num_Docs_Missing">
using an xsl:variable with content but no as attribute makes a document node with a text node with the decimal expansion of a number.
This is ineffficient it's better to add as="xs:integer" (or xs:double, or whatever type you need)


    <xsl:choose>
      <xsl:when test="@complete='Y'">
         *****Some Calculations**********
      </xsl:when>
      <xsl:otherwise>
        *****Some Calculations**********
      </xsl:otherwise>
    </xsl:choose>
   </xsl:variable>

<xsl:sequence select="sum(for $x in $eventTemplate return(count(($x/event) * $Num_Docs_Missing)))"/>
the value of the variable $Num_Docs_Missing is calcuated before the loop so the above is the same as
$Num_Docs_Missing *( sum(for $x in $eventTemplate return(count(($x/event))


except that if (as I think you intended) $eventTemplate was a sequence of event elements, $x/event would be empty as event elements don't have event children.
</xsl:function>


It would appear that you want the calculation done for every event, so it needs to be a function of event nodes, not a variable.


<xsl:function name="fns:f" as="xs:integer">
<xsl;param name="x" as="element()"/>
<xsl:choose>
<xsl:when...
<xsl:sequence select=...
...
</xsl:function>

then

<xsl:temmplate match="/">
<xsl:sequence select="sum(//event/fns:f(.))"/>
</xsl:template>

David


Here is my XML again

<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>

I am trying to achieve is the total of event*(Num_Docs_Missing) for all the event_template.



________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. ________________________________________________________________________


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.