RE: [xsl] Calculating Column Total

Subject: RE: [xsl] Calculating Column Total
From: Shashank Jain <shashankjain@xxxxxxxx>
Date: Tue, 30 Mar 2010 16:20:13 -0500
Thanks David for explaining what I was doing wrong.

I am still stuck in the calculation for every event.

<data>
<event_template sp_mand_doctypes="Research Note, Prior Stock Report, Stock
Report">
<event complete='Y' complete_percent='100.0'/>
<event complete='N' complete_percent='0.0'/>
</event_template>
<event_template sp_mand_doctypes=" Prior Stock Report, Stock
Report">
<event complete='Y'complete_percent='100.0'/>
<event complete='N'complete_percent='0.0'/>
<event complete='N'complete_percent='50.0'/>
<event
complete='Y'/>
</event_template>
</data>

and I am using this xsl

<xsl:template match="/">
  <xsl:sequence select="sum(//event/fns:f(.))"/>
</xsl:template>
<xsl:function name="fns:f">
  <xsl:param name="x" as="element()"/>
  <xsl:choose>
      <xsl:when test="$x/@complete='Y'">
       <xsl:value-of select="number(0)"/>
       </xsl:when>
       <xsl:when test="$x/@complete_percent='0.0'">
*********am not able to pass value in the variable
"mandatoryDocs"*********************
        <xsl:variable name="mandatoryDocs"
select="parent::event_template/@sp_mand_doctypes"/>
        <xsl:variable name="strArray" select="tokenize($mandatoryDocs,',')"/>
        <xsl:value-of select="number(count($strArray))"/>
       </xsl:when>
  </xsl:choose>
</xsl:function>

I am trying to get the sum =5 (3 for first event_template + 2 for second
event_template), but I am getting 0

Thanks again,

Shashank

> Date: Mon, 29 Mar 2010 09:54:54 +0100
> From: davidc@xxxxxxxxx
> To: shashankjain@xxxxxxxx
> CC: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] 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.
> ________________________________________________________________________
>

_________________________________________________________________
The New Busy is not the old busy. Search, chat and e-mail from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID27925::T:WLMTAGL:ON:WL
:en-US:WM_HMP:032010_3

Current Thread