p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

xslt thread: Summing Problem


Message #1 by "karthikeyan" <karthikeyan@a...> on Thu, 19 Sep 2002 16:36:01 +0530
/Recordset/row/Sums selects Sums elements that have 
a row parent and a Recordset grandparent that start 
at the root. (But I assume you already knew this 
since you already had it =)

(In your case, I also tried it without the / and it 
still worked- I'm assuming so b/c the template you're 
in matches root anyway (someone correct me if I'm wrong!).)

The . in [. &gt; 0] selects the context node- in 
this case, Sums. So [. &gt; 0] means "where Sums 
is greater than 0".


--- karthikeyan <karthikeyan@a...> wrote:
Cool :)

Alex thats fantastic :):):):):):):)

Could you explain me this section.

<B><xsl:value-of select="sum(/Recordset/row/Sums[. &gt; 0])"/></B>

I would like to know :)

karthikeyan.


----- Original Message -----
From: "alex" <shortestpath@y...>
To: "P2P_XSLT" <xslt@p...>
Cc: <karthikeyan@a...>
Sent: Thursday, September 19, 2002 6:45 PM
Subject: [xslt] Re: Summing Problem


>
> In your template Recordset, in the for-loop, you have:
>
> <xsl:variable name="perposcnt" select="number(Sums) &gt; 0"/>
> <xsl:if test="$perposcnt != true">
>  <xsl:value-of select="Sums"/>
> </xsl:if>
>
> and
>
> <xsl:variable name="pernegcnt" select="number(Sums) &lt; 0"/>
> <xsl:if test="$pernegcnt != true">
>  <xsl:value-of select="Sums"/>
> </xsl:if>
>
> I would change these to:
>
> <xsl:if test="number(Sums) &gt;= 0">
>     <xsl:value-of select="Sums"/>
> </xsl:if>
>
> and
>
> <xsl:if test="number(Sums) &lt; 0">
>     <xsl:value-of select="Sums"/>
> </xsl:if>
>
> respectively. I don't know if this is better,
> but it just seems unneccesary to use a variable.
>
> Now, in the section where you summ your credits
> and debits, try changing:
>
> <xsl:variable name="perposcnt" select="number(/Recordset/row/Sums) &gt;
> 0"/>
> <xsl:if test="$perposcnt != true">
> <B><xsl:value-of select="sum(/Recordset/row/Sums[$perposcnt])"/></B>
> </xsl:if>
>
> to:
> <B><xsl:value-of select="sum(/Recordset/row/Sums[. &gt; 0])"/></B>
>
> and
>
> <xsl:variable name="pernegcnt" select="number(/Recordset/row/Sums) &lt;
> 0"/>
> <xsl:if test="$pernegcnt != true">
> <B><xsl:value-of select="sum(/Recordset/row/Sums[$pernegcnt])"/></B>
> </xsl:if>
>
> to:
> <B><xsl:value-of select="sum(/Recordset/row/Sums[. &lt; 0])"/></B>
>
>
> --- karthikeyan <karthikeyan@a...> wrote:
> Hi All,
>
>   I have an xml where under <Sum> tag i may get POSITIVE number or
NEGATIVE
>
> number.
>
>   Postive Number i need to display under the Heading : [ Gross Commission
> Credit ] and
>
>   Negative Number i need to display under the Heading : [ Gross 
Commission
> Debit ]
>
>   [This i am able to do :)] but what i m not able to do is to
>
>   Count SUM of Gross Commission Credit and SUM of Gross Commision Debit.
>
>   Right now when i did this i am getting wrong values.
>
>   <Recordset>
>     <row><Sum> -34 </Sum></row>
>     <row><Sum> -34 </Sum></row>
>     <row><Sum> 15 </Sum></row>
>   </Recordset>
>
>   Gross Commision Credit : Nothing displayed here
>
>   Gross Commision Debit : -53
>
>   Any help regarding this would be greatly appreciated.
>
> karthikeyan.
>
>   Heres the XSL file
>
> ~~~~~~~~~~~~~~~~~~~
> <xsl:stylesheet version="1.0"
>                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
>   <xsl:output method="html"/>
>
>   <xsl:template match="/">
>
>     <HTML>
>       <HEAD>
>           <TITLE>
>             Misys IFA Services plc :: <xsl:value-of
> select="//@ReportName"/>
>           </TITLE>
>       </HEAD>
>       <BODY align="CENTER">
>
>         <FONT face="ARIAL">
>
>           <TABLE width="750" border="0" bgcolor="#FFFFFF" cellpadding="0"
>                  cellspacing="0">
>             <TR>
>               <TD align="LEFT" bgcolor="#FFFFFF">
>                 <H2>Misys IFA Services plc</H2>
>               </TD>
>               <TD align="RIGHT"><IMG height="55"
> src="MISYS.GIF"></IMG></TD>
>             </TR>
>             <TR>
>               <TD align="LEFT" bgcolor="#999999" colspan="2">
>                 <H4><xsl:value-of select="//@ReportName"/></H4>
>                 <H5>
>                   <i>
>                     As at : <xsl:value-of select="/Recordset/row/AsAt"/>
>                   </i>
>                 </H5>
>               </TD>
>             </TR>
>           </TABLE>
>
>           <TABLE width="750" border="0" bgcolor="#FFFFFF" cellpadding="2"
>                  cellspacing="0">
>             <xsl:apply-templates select="Recordset"/>
>
>             <TR>
>               <TD align="LEFT" valign="TOP" bgcolor="#CCCCCC">
>                 <B>Total</B>
>               </TD>
>               <TD align="LEFT" valign="TOP" bgcolor="#CCCCCC">
>                 <B> </B>
>               </TD>
>               <TD align="LEFT" valign="TOP" bgcolor="#CCCCCC">
>                 <xsl:variable name="perposcnt"
> select="number(/Recordset/row/Sums) &gt; 0"/>
>                 <xsl:if test="$perposcnt != true">
>                   <B><xsl:value-of
> select="sum(/Recordset/row/Sums[$perposcnt])"/></B>
>                 </xsl:if>
>               </TD>
>               <TD align="LEFT" valign="TOP" bgcolor="#CCCCCC">
>                 <xsl:variable name="pernegcnt"
> select="number(/Recordset/row/Sums) &lt; 0"/>
>                 <xsl:if test="$pernegcnt != true">
>                   <B><xsl:value-of
> select="sum(/Recordset/row/Sums[$pernegcnt])"/></B>
>                 </xsl:if>
>               </TD>
>               <TD align="LEFT" valign="TOP" bgcolor="#CCCCCC">
>                 <B><xsl:value-of
> select="sum(/Recordset/row/NumberOfTransactions)"/></B>
>               </TD>
>             </TR>
>
>           </TABLE>
>
>         </FONT>
>
>       </BODY>
>     </HTML>
>
>   </xsl:template>
>
>   <xsl:template match="Recordset">
>
>     <TR><TD colspan="6"> </TD></TR>
>     <TR>
>       <TD align="LEFT" valign="TOP" bgcolor="#CCCCCC">
>         <B>Agency Code</B>
>       </TD>
>       <TD align="LEFT" valign="TOP" bgcolor="#CCCCCC">
>         <B>Commission Agency Name</B>
>       </TD>
>       <TD align="LEFT" valign="TOP" bgcolor="#CCCCCC">
>         <B>Gross Commission Credit</B>
>       </TD>
>       <TD align="LEFT" valign="TOP" bgcolor="#CCCCCC">
>         <B>Gross Commission Debit</B>
>       </TD>
>       <TD align="LEFT" valign="TOP" bgcolor="#CCCCCC">
>         <B>Number of Transactions</B>
>       </TD>
>     </TR>
>       <xsl:for-each select="row">
>         <xsl:sort select="substring-before(AgencyCode, '2')"
> data-type="number"/>
>      <TR>
>        <TD><xsl:value-of select="AgencyCode"/></TD>
>           <TD><xsl:value-of select="CommissionAgencyName"/></TD>
>           <TD>
>             <xsl:variable name="perposcnt" select="number(Sums) &gt; 0"/>
>             <xsl:if test="$perposcnt != true">
>               <xsl:value-of select="Sums"/>
>             </xsl:if>
>           </TD>
>           <TD>
>             <xsl:variable name="pernegcnt" select="number(Sums) &lt; 0"/>
>             <xsl:if test="$pernegcnt != true">
>               <xsl:value-of select="Sums"/>
>             </xsl:if>
>           </TD>
>        <TD><xsl:value-of select="NumberOfTransactions"/></TD>
>      </TR>
>
>    </xsl:for-each>
>
>   </xsl:template>
>
> </xsl:stylesheet>
> ~~~~~~~~~~~~~~~~~~~
>
>
> Here is my XML File
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <?xml-stylesheet type="text/xsl"
> href="Report_Commissions_AwaitingApproval.xsl"?>
> <Recordset ReportName="Report Name" UserName="UserName"
> InsertedOn="InsertedOn">
>  <row>
>   <AgencyCode>MC09</AgencyCode>
>   <CommissionAgencyName>MC09</CommissionAgencyName>
>   <Sums>-34</Sums>
>   <NumberOfTransactions>1</NumberOfTransactions>
>   <Network>FOG</Network>
>   <AsAt>26/08/2002</AsAt>
>  </row>
>  <row>
>   <AgencyCode>MC09</AgencyCode>
>   <CommissionAgencyName>MC09</CommissionAgencyName>
>   <Sums>-34</Sums>
>   <NumberOfTransactions>1</NumberOfTransactions>
>   <Network>FOG</Network>
>   <AsAt>26/08/2002</AsAt>
>  </row>
>  <row>
>   <AgencyCode>MC09</AgencyCode>
>   <CommissionAgencyName>MC09</CommissionAgencyName>
>   <Sums>15</Sums>
>   <NumberOfTransactions>1</NumberOfTransactions>
>   <Network>FOG</Network>
>   <AsAt>26/08/2002</AsAt>
>  </row>
> </Recordset>

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com

  Return to Index