title: Re-grouping nodes in variable containing sequence of nodes
body: <p>I am trying to create a two-column print-able HTML phone list from an XML file of organizational groups containing associated personnel</p>
  
  <pre><code> &lt;group print_order=1&gt;
   &lt;group_name&gt;&lt;![CDATA[Human Resources]]&gt;&lt;/group_name&gt;
      &lt;person&gt;...(name, address, phone data)...&lt;/person&gt;
      &lt;person&gt; ... &lt;/person&gt;
      &lt;person&gt; ... &lt;/person&gt;
   &lt;/group&gt;
   &lt;group print_order=2&gt;
   &lt;group_name&gt;&lt;![CDATA[Operations]]&gt;&lt;/group_name&gt;
      &lt;person&gt; ... &lt;/person&gt;
      &lt;person&gt; ... &lt;/person&gt;
      &lt;person&gt; ... &lt;/person&gt;
      &lt;person&gt; ... &lt;/person&gt;
   &lt;/group&gt;
   &lt;group print_order=3&gt;
   &lt;group_name&gt;&lt;![CDATA[IT Services]]&gt;&lt;/group_name&gt;
  </code></pre>
  
  <p>etc.<br>
  I'm trying to get to the following html output</p>
  
  <pre><code> &lt;table&gt;
    &lt;tr&gt;
     &lt;td&gt;
     &lt;div class=group&gt;Human Resources
      &lt;person&gt;
       &lt;span class=name&gt; lastname, firstname &lt;/span&gt;
       &lt;span class=addr&gt; room# building &lt;/span&gt;
       &lt;span class=phone&gt; 555-5555 &lt;/span&gt;
      &lt;/person&gt;
          (repeated for each person in group)
     &lt;/div&gt;
     &lt;div class=group&gt;Operations
      &lt;person&gt;
       &lt;span class=name&gt; lastname, firstname &lt;/span&gt;
       &lt;span class=addr&gt; room# building &lt;/span&gt;
       &lt;span class=phone&gt; 555-5555 &lt;/span&gt;
      &lt;/person&gt;
     &lt;/div&gt;
    &lt;/td&gt;
    &lt;td&gt;
     &lt;div class=group&gt;IT Services
      &lt;person&gt;
       &lt;span class=name&gt; lastname, firstname &lt;/span&gt;
       &lt;span class=addr&gt; room# building &lt;/span&gt;
       &lt;span class=phone&gt; 555-5555 &lt;/span&gt;
      &lt;/person&gt;
          (repeated for each person in group)
     &lt;/div&gt;
       etc. 
    &lt;/td&gt;
   &lt;/tr&gt;
  &lt;/table&gt;
  &lt;p class=page_break&gt;
  &lt;table&gt;  (next table on next page)
   &lt;tr&gt;
    &lt;td&gt;  (next set of groups with people)
    &lt;/td&gt;
    &lt;td&gt; ( next set of groups with people )
    &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  (Repeat tables as needed until all groups output) 
  </code></pre>
  
  <p>The problem is that I want the number of lines in a table cell to be less than or equal to the number lines on a printed page, and I don't want groups split across table elements. 
  I've tried the xsl:for-each-group instruction, but I can't figure out what the group-by or group-adjacent code should look like. I've also tried the following horrendous test:</p>
  
  <pre><code>&lt;xsl:if test="sum($nodes/group[following-sibling::group[preceding-sibling::group[1] is current()]]/@line_count) mod 40 &amp;gt; sum($nodes/group[following-sibling::group[preceding-sibling::group[2] is current()]]/@line_count) mod 40 "&gt;
  </code></pre>
  
  <p>in a <code>for-each</code> loop, where nodes is a variable containing the sequence of groups, line_count is the number lines per group, and 40 is the # of lines per page. I'm using HTML tables to maximize browser support. </p>
  
  <p>Is there a better way to do this? Using CSS maybe?  Larry Wall, the author of the Perl language, said that in a programming language, easy things should be easy, and hard things should be possible. Is what I'm after possible in XSLT/XPath? Thanks to anyone willing to wade through all this. </p>