RE: [xsl] Looking for an equivalent to recursion within a for loop

Subject: RE: [xsl] Looking for an equivalent to recursion within a for loop
From: "Eran Hammer-Lahav" <xalan@xxxxxxxxx>
Date: Fri, 30 May 2003 17:47:09 -0400
This is a piece of code I have in one of my projects:

<xsl:template name="getNameSizeMax">

<xsl:param name="maxSize_" />
<xsl:param name="pos_" />

<xsl:choose>
<xsl:when test="field[$pos_]">
<xsl:variable name="_size" select="string-length(field[$pos_]/@name)" />

<xsl:variable name="_maxSize">
<xsl:choose>
<xsl:when test="number($_size) &gt; number($maxSize_)">
<xsl:value-of select="$_size" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$maxSize_" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:call-template name="getNameSizeMax">
<xsl:with-param name="maxSize_" select="$_maxSize" />
<xsl:with-param name="pos_" select="$pos_ + 1" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$maxSize_" />
</xsl:otherwise>
</xsl:choose>
		
</xsl:template>

My document has a <structure> element which has many <field> elements. Once
I am inside the <structure>, I call the template with maxSize_ = 0 and pos_
= 1, which will return the max name size of all the fields. You should be
able to use a similar logic to do what you want. Basically, instead of using
a for-each loop, I am using a predicate to process the next object in line.

Hope this helps.

EL

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Erika Marlow
Sent: Friday, May 30, 2003 5:22 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx

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
}

Does anyone have any suggestions for how this might be accomplished?  I've
found myself running into recursion within a for loop, which is not
possible.

Thanks for any suggestions.
Erika

end



------------  Gateway EDI, Inc.
----------------------------------------------------------------------------
-----------------------

This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.
If you are not the intended addressee, or the person responsible for
delivering it to them, you may not copy, forward, disclose or otherwise use
it or any part of it in any way.  To do so may be unlawful.  If you receive
this email by mistake, please advise the sender immediately and destroy all
copies of the original message.


 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