title: filter data in apache velocity for loop
body: <p>I am using Apache velocity to parse an xml file, let's say I have the following case:</p>
  
  <p>My XML contains an <code>&lt;animals&gt;</code> root node which contains a <code>&lt;dogs&gt;</code> node with 3 children that are singular <code>&lt;dog&gt;</code>, each of them have a <code>&lt;name&gt;</code> node containing a value.</p>
  
  <pre><code>&lt;animals&gt;
      &lt;dogs&gt;
          &lt;dog&gt;
              &lt;name&gt;REX&lt;/name&gt;
          &lt;/dog&gt; 
          &lt;dog&gt;
              &lt;name&gt;FELIX&lt;/name&gt;
          &lt;/dog&gt; 
          &lt;dog&gt;
              &lt;name&gt;REX&lt;/name&gt;
          &lt;/dog&gt; 
      &lt;/dogs&gt;
  &lt;/animals&gt;
  </code></pre>
  
  <p>In my velocity template, I have a <code>foreach</code> loop fetching all the <code>&lt;dog&gt;</code> nodes, something like this: </p>
  
  <pre><code>#foreach( $dog in $animals.dogs.children() )
      $dog.name.getText() 
  #end
  </code></pre>
  
  <p>so, this basic example works, but what if I have to filter out of the foreach the dog that dosen't have FELIX as a name ? Looping only over dogs that have the name REX for example, I have tried using IF statements , but it dosen't work with getText(), is there a way of doing that directly in the foreach loop ? </p>
  
  <p>thanks.</p>