title: Template nested grouping with Sort option
body: <p>I would like to generate a report using RTF Template which looks like the below:</p>
  
  <p>Expected Output:</p>
  
  <pre><code>US
  Cover   Insured
  123456  INS1, INSB, INSA
  987654  INS2
  
  or
  
  US
  Cover   Insured
  123456  INS1
          INSB
          INSA
  987654  INS2
  </code></pre>
  
  <p>Here "Insured" data is present both in Parent and child hierarchy with different tag names. Parent "InsuredAccnt" (INS1 in my XML) should be displayed first followed by child "InsuredAccounts" which will be sorted by "Share" - Descending.</p>
  
  <p>XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt; 
  &lt;InsuredReport&gt;
  &lt;GroupPolicies&gt;
    &lt;Cover&gt;123456&lt;/Cover&gt; 
    &lt;Customer&gt;Customer&lt;/Customer&gt;
    &lt;InsuredAccnt&gt;INS1&lt;/InsuredAccnt&gt;       
    &lt;Organization&gt;US&lt;/Organization&gt; 
    &lt;ListOfGroupPolicies_InsuredAccount&gt;
       &lt;GroupPolicies_InsuredAccount&gt;
          &lt;InsuredAccount&gt;INSA&lt;/InsuredAccount&gt; 
          &lt;Share&gt;5&lt;/Share&gt; 
       &lt;/GroupPolicies_InsuredAccount&gt;
       &lt;GroupPolicies_InsuredAccount&gt;
          &lt;InsuredAccount&gt;INSB&lt;/InsuredAccount&gt; 
          &lt;Share&gt;20&lt;/Share&gt; 
       &lt;/GroupPolicies_InsuredAccount&gt;
    &lt;/ListOfGroupPolicies_InsuredAccount&gt;
  &lt;/GroupPolicies&gt;
  &lt;GroupPolicies&gt;
    &lt;Cover&gt;987654&lt;/Cover&gt; 
    &lt;Customer&gt;ABC&lt;/Customer&gt;
    &lt;InsuredAccnt&gt;INS2&lt;/InsuredAccnt&gt;       
    &lt;Organization&gt;US&lt;/Organization&gt; 
    &lt;ListOfGroupPolicies_InsuredAccount /&gt;
  &lt;/GroupPolicies&gt;
  &lt;/InsuredReport&gt;
  </code></pre>
  
  <p>I am not sure how to upload the RTF used, but this is a gist of the same:</p>
  
  <p>RTF:</p>
  
  <pre><code>&lt;?for-each-group:GroupPolicies;./Organization?&gt;
  
  Grouping within Table based on Cover
  &lt;?for-each-group:current-group();./Cover?&gt;
  
  Displaying "Insured"
  &lt;?InsuredAccnt?&gt;
  &lt;?for-each-group:current-group();./GroupPolicies_InsuredAccount?&gt;&lt;?sort: Share?&gt;&lt;?InsuredAccount?&gt;&lt;?end for-each-group?&gt;
  </code></pre>
  
  <p>When I give this, my system runs forever and I am forced to kill the session.
  Please could someone point out where I am wrong.</p>