This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: variable going out of scope in a for-each loop?
- From: Nate Austin <naustin at idsgrp dot com>
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Mon, 10 Dec 2001 10:17:19 -0600
- Subject: Re: [xsl] variable going out of scope in a for-each loop?
- Reply-to: xsl-list at lists dot mulberrytech dot com
Eric -
If it's always the last two nodes that you want to multiply, then it's
pretty straight forward:
<xsl:value-of select="cell[last()-1] * cell[last()]"/>
(where row is the current node).
If you just want the product of all nodes that are numbers, you have to use
a recursive process. You can start by selecting all number nodes by using a
select expression similar to the xsl:if you used: <xsl:variable
name="numberNodes" select="cell[number(.)=number(.)]"/> (replace
xsl:variable with xsl:with-param to pass it to your recursive template).
Alternately, if it's possible to use extension functions and you're using
Saxon, I'm sure Mike has one that'll make this job a piece of cake. I'll
leave it to him (or whoever else steps up) to give that to you.
Hope that helps.
-Nate
>Date: Mon, 10 Dec 2001 00:20:22 +0100
>From: Eric Smith <Eric.Smith@fruitcom.com>
>Subject: Re: [xsl] variable going out of scope in a for-each loop?
>
>- - perhaps i am going about this the wrong way - i need to calcualte the
product of the
>last two cells in a row viz.
>
> <row header="phase">
> <cell>
> John Doe
> </cell>
> <cell>
> Engineer
> </cell>
> <cell>
> 246
> </cell>
> <cell>
> 135
> </cell>
> </row>
>
>This should be so easy to do (maybe it is?).
>
>- --
>Eric Smith - currently using xalan and xsltproc - what a difference speed
makes - and fop on linux
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list