title: Groovy find nodes using gpath with certian child count and expression
body: <p>Suppose I have an <strong>XML</strong>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;data&gt;
      &lt;level0 id="1" t="0"&gt;
        &lt;level1 id="lev1id01" att1="2015-05-12" val="12" status="0"/&gt;
        &lt;level1 id="lev1id02" att1="2015-06-13" val="13" status="0"/&gt;
        &lt;level1 id="lev1id03" att1="2015-07-10" val="13" status="0"/&gt;
      &lt;/level0&gt;
  
      &lt;level0 id="2" t="0"&gt;
          &lt;level1 id="lev1id11" att1="2015-05-12" val="121" status="0"/&gt;
          &lt;level1 id="lev1id12" att1="2015-06-13" val="132" status="0"/&gt;
          &lt;level1 id="lev1id13" att1="2015-07-11" val="113" status="0"/&gt;
      &lt;/level0&gt;
  
      &lt;level0 id="2" t="1"&gt;
          &lt;level1 id="lev1id21" att1="2015-05-12" val="121" status="0"/&gt;
          &lt;level1 id="lev1id22" att1="2015-06-13" val="132" status="0"/&gt;
          &lt;level1 id="lev1id23" att1="2015-07-11" val="113" status="0"/&gt;
          &lt;level1 id="lev1id23" att1="2015-07-11" val="113" status="0"/&gt;
      &lt;/level0&gt;
  &lt;/data&gt;
  </code></pre>
  
  <p>I want to get all <code>level0</code> nodes (using <strong>GPath</strong>) which are:</p>
  
  <ol>
  <li>If <code>level0/@t="0"</code> then select this node (<strong>level0</strong>) only if <strong>all</strong> its <code>level1</code> children has <code>@status="0"</code></li>
  <li>If <code>level0/@t!="0"</code> then select this node (<strong>level0</strong>) only if the <strong>last</strong> <code>level1</code> child has <code>@status="0"</code>. When I say last I mean the <code>level1</code> node with maximum value in <code>@att1</code> (assuming <code>@att1</code> contains date in <code>yyyy-mm-dd</code> format).</li>
  </ol>
  
  <p>With <strong>XPath</strong> I would use functions like max() and count(), but I can't get how it could be done using <strong>GPath</strong>.</p>
  
  <p>Thanks </p>