Subject: RE: [xsl] sum() command From: "Macaulay,Malcolm (US)" <Malcolm.Macaulay2@xxxxxxxxx> Date: Tue, 20 Aug 2002 13:47:53 -0500 |
Hi Victor, There are two problems: 1] your XPaths are pointing to the *row* elements not the *value* elements. Your XPaths should be: <xsl:value-of select="sum(/query/row/value[@field='duracao'])"/> <xsl:value-of select="sum(/query/row/value[@field='valor'])"/> /query/row[value/@field='duracao'] will return rows, then the sum function of will obtain the text property of the row (e.g "25/07/2002 15:54:40 2ª A 6ª Voz 00:15:00 80.04" is the text property of the first row), it will then attempt to convert this string to a number. It will fail and return NaN (default return value for Not-A-Number). If you make the corrections above the @field='valor' statement will work. 2] the @field='duracao' values cannot be summed because the processor cannot convert something like '00:15:00' into a number. If duracao is a time, then you could create a template to sum such elements, but that's another story... Hope that helps, cheers Malcolm -----Original Message----- From: Vitor Cavalcanti [mailto:vitor_cavalcanti@xxxxxxxxx] Sent: Tuesday, August 20, 2002 12:42 PM To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx' Subject: [xsl] sum() command Folks, I got an error when i use the sum() command. Can you help me, guys? :) I have following XML-structure: <query> <row> <value field="data">25/07/2002</value> <value field="hora">15:54:40</value> <value field="grupo">2ª A 6ª</value> <value field="tipo">Voz</value> <value field="duracao">00:15:00</value> <value field="valor">80.04</value> </row> <row> <value field="data">25/07/2002</value> <value field="hora">15:45:30</value> <value field="grupo">2ª A 6ª</value> <value field="tipo">Voz</value> <value field="duracao">00:10:00</value> <value field="valor">0.05</value> </row> <row> .... </row> </query> I'm doing a <xsl:for-each select="value"> and puting all these values in a <table> html. Now I wanna put the last line with a <td> with the total sum of the "duracao" field and another <td> with the "valor" sum. Out of for-each, I'm doing the following: <xsl:value-of select="sum(/query/row[value/@field='duracao'])"/> and <xsl:value-of select="sum(/query/row[value/@field='valor'])"/>. Both are returning NaN. Any idea, guys? Thanks, Vitor XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] document() function to get st, tpass001 | Thread | Re: [xsl] sum() command, KUMAR NINGASHETTY |
[xsl] sum() command, Vitor Cavalcanti | Date | Re: [xsl] sum() command, KUMAR NINGASHETTY |
Month |