xsl-list
[Top] [All Lists]

Re: Looking for an equivalent to recursion within a for loop

2003-05-30 22:54:28

"Erika Marlow" <EMarlow(_at_)GatewayEDI(_dot_)com> wrote in message
news:E159FD8A01059F4FBA480CF7A6BC403A6E5B3F(_at_)ntmail(_dot_)(_dot_)(_dot_)
Dear List Members:

I have run into a situation where I must increment a counter.  This can be
worked around using recursion and calling a template. However, I need to
increment the counter while I iterate through a node-set.  This would
normally just be a matter of adding another parameter to the template
call,
but I have to increment the counter based on a condition while iterating
through the node-set.

The pseudo-code for this particular situation would be something like
this:

function process-list-conditionally(list L)
{
  if (not-empty(L))
for-each(L)
  if (true)
increment-counter
  otherwise
counter
}


What about:

count($L[yourCondition])

or

<xsl:for-each select="$L[yourCondition]">

  <xsl:variable name="theCounter" select="position()"/>
</xsl:for-each>



If the case is more complicated, one will use one of  "filter" , "foldl" ,
"iter, "scanIter" or  "scanl" templates from FXSL -- I cannot say which,
because I haven't seen your actual problem.



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL






 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>