Re: [xsl] Problem with xslt recursion

Subject: Re: [xsl] Problem with xslt recursion
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 10 Feb 2004 12:00:34 -0500
Hi Roopesh,

At 11:15 AM 2/10/2004, you wrote:
This is my first doubt with this group..hope i get
some help..

I have the following xml... <UIComponents> <Component name = "EntrySpecialMessageAddButton"> <ResourceType>Composite</ResourceType> <ResourceTypeSet> <Type>R1</Type> <Type>R2</Type> <Type>R3</Type> </ResourceTypeSet> </Component> </UIComponents>

and i have a recursive call to a template whose
function is to concatenate all the values with the tag
name Type..(The actual functionality of the template
is more than what is being described here..which
cannot be disclosed)

Of course I can't speak to the actual functionality not being disclosed, but if all that needs to be done is to concatenate the values, this doesn't require recursion.

Can you be a little bit more explicit about why you require recursion here and what it's doing for you? (code reformatted for legibility)

<xsl:template name="build">
  <xsl:param name="ResourceName"/>
  <xsl:param name="Index"/>
  <xsl:param name="Count"/>
  <xsl:variable name="try">
    <xsl:value-of select ="ResourceTypeSet/Type[$In]"/>
  <xsl:if test="$Index &lt; $Count">
    <xsl:call-template name="buildResourceName">

The template called here is "buildResourceName", but no template by that name appears in the code sample.

      <xsl:with-param name="ResourceName">
        <xsl:value-of select="concat($ResourceName,$TempResource)"/>

It's also not apparent from your code what $ResourceName and $TempResource are....

      <xsl:with-param name="Index">
        <xsl:value-of select="$Index+1"/>
      <xsl:with-param name="Count" select="$Count"></xsl:with-param>

The initial call to the template is as follows

<xsl:call-template name="build">
  <xsl:with-param name="ResourceName"/>
  <xsl:with-param name="Index" select="1"/>
  <xsl:with-param name="Count" select="$Count+1">

The problem is that for each recursive call to the
template the value of try remains R1...
whereas it should have been R1 in the first call..
R2 for the next call..and R3 for the third cal..

It's difficult to say given just the code you've supplied (no "buildResourceName" template) ... a number of things here are simply mystifying. Without knowing what the template is actually supposed to be doing, it's impossible to diagnose.

Maybe the call to "buildResourceName" is supposed to be the recursive call to "build" itself. If this is the case, the role of the $Count variable needs to be clarified -- this is intended to specify the limit of your recursion? How is this determined?

It also appears that you mean to bind the variable $try to the values of the Type elements in turn, but it's not clear why since nothing is then done with this variable.

If you are only concatenating, you don't need to jump through so many hoops, but can simply copy the nodes' values to output using any of several methods (all easier than recursion). But you've said you aren't really concatenating. Seeing the actual requirement, or failing that something closer to it, would help us determine what the best approach is in your case.


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

XSL-List info and archive:

Current Thread