You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Adam Esterline <Ad...@cait.wustl.edu> on 2002/08/07 23:57:42 UTC

Recursion

I have seen several posts about this issue, but I still don't understand.
Here is my example, could someone please explain why this does not work.


## Macro for creating the outline XML
#macro( processNode $node )
<item>
   <text>$node.text</text>
   #foreach( $child in $node.children )
      #processNode( $child )
   #end
</item>
#end

<course>
  <name>$course.name</name>
  <code>$course.code</code>
  <category>$course.category.name</category>
  <super_cat>$course.category.superCategory.name</super_cat>
  <description>$course.description</description>
  <comment>$course.comment</comment>
  <prerequisites>
  #foreach( $prereq in $course.prerequisites )
      <prerequisite>$prereq.code</prerequisite>
  #end
  </prerequisites>
  <audience>$course.audience</audience>
  <duration>$course.duration</duration>
  <objectives>
  #foreach( $obj in $course.currentObjectives )
    <objective>$obj</objective>
  #end
  </objectives>
  <outline>
    #foreach( $kid in $course.outline.children )
       #processNode( $kid )
    #end
  </outline>
  ## We do not have the revised field worked out yet.
  ## TODO: Find out what can be done to accomidate the revised field.
  <revised>6/18/01</revised>
</course>

The XML that is generated looks like this.

<course>
  <name>Developing MS Access Applications - I</name>
  <code>ACC200</code>
  <category>Access</category>
  <super_cat>Database</super_cat>
  <description>Microsoft Access is the premiere database management system
used today.  It allows someone with little database and programming
expertise to build a sophisticated application in a short amount of time.
In this course, students will learn to develop Microsoft Access applications
using the features of Microsoft Access, such as tables, queries, forms, and
reports.  Students will use Microsoft Access wizards and builders to
facilitate the development of their application, and learn how to modify
objects without using wizards.  They will learn about table relationships,
data validation, queries and form and report design.</description>
  <comment>Participants should be familiar with Access as end-users, or have
experience with another database.
</comment>
  <prerequisites>
    </prerequisites>
  <audience>This course is designed for students who want to learn to
develop Microsoft Access applications.</audience>
  <duration>3</duration>
  <objectives>
      <objective>Use database design principles to design an Microsoft
Access application.</objective>
      <objective>Use Microsoft Access features to build the
application.</objective>
      <objective>Use built-in wizards and builders to facilitate application
development.</objective>
    </objectives>
  <outline>
           <item>
   <text>Tables</text>
         <item>
   <text>Tables</text>
         <item>
   <text>Tables</text>
         <item>
   <text>Tables</text>
         <item>
   <text>Tables</text>
         <item>
   <text>Tables</text>
         <item>
   <text>Tables</text>
         <item>
   <text>Tables</text>
         <item>
   <text>Tables</text>
         <item>
   <text>Tables</text>
         <item>
   <text>Tables</text>
         <item>
   <text>Tables</text>
         <item>
   <text>Tables</text>
         <item>
   <text>Tables</text>
         <item>
   <text>Tables</text>
         <item>
   <text>Tables</text>
         <item>

....
</course>

As you can see I get too many outline items.   This list does eventually
quit, so it is not in an infinite loop.

Any help would be appreciated.

Adam

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Recursion

Posted by lloyd <su...@twilight-systems.com>.
Adam Esterline wrote:
> I have seen several posts about this issue, but I still don't understand.
> Here is my example, could someone please explain why this does not work.
> 
> 
> ## Macro for creating the outline XML
> #macro( processNode $node )
> <item>
>    <text>$node.text</text>
>    #foreach( $child in $node.children )
>       #processNode( $child )
>    #end
> </item>
> #end


Wild guess:

Have you tried getting a reference to children first:

#(set $childNodes = $node.children )
#foreach( $child in $childNodes )
...etc

?


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>