xsl-list
[Top] [All Lists]

Re: [xsl] Calculating Column Total

2010-03-29 03:55:19
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. ________________________________________________________________________

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