Can anyone assist me with the following xml transformation problem?
 
In short, I would like to transform this input.xml doc:
 
<table>
  <row>
    <column>Chapter I</column>
    <column></column>
    <column></column>
    <column></column>
  </row>
  <row>
    <column></column>
    <column>I. Section 1</column>
    <column></column>
    <column></column>
  </row>
  <row>
    <column></column>
    <column>I. Section 2</column>
    <column></column>
    <column></column>
  </row>
  <row>
    <column>Chapter II</column>
    <column></column>
    <column></column&a mp;g t;
    <column></column>
  </row>
  <row>
    <column></column>
    <column>II. Section 1</column>
    <column></column>
    <column></column>
  </row>
  <row>
    <column></column>
    <column>II. Section 2</column>
    <column></column>
    <column></column>
  </row>
  <row>
    <column></column>
    <column></column>
    <column>II. Section 2 Part A</column>
    <column></column>
  </row>
  <row>
    <column></column>
    <column&g t;< ;/column>
    <column>II. Section 2 Part B</column>
    <column></column>
  </row>
</table>
 
to this output.xml doc:
 
<book>
  <chapter>
    <title>Chapter I</title>
    <section>
      <title>I. Section 1</title>
    </section>
    <section>
      <title>I. Section 2</title>
    </section>
  </chapter>
  <chapter>
    <title>Chapter II</title>
    <section>
      <title>II. Section 1</title>
    </section>
    <section>
      <title>II. Section 2</title>
      <subsection>
 <title>II. Section 2 Part A</title>
      </subsection>
      <subsection& amp; gt;
 <title>II. Section 2 Part B</title>
      </subsection>
    </section>
  </chapter>
</book>
 
The idea is that  "table of contents" data is in a table format. I would like to re-express the data as a hierarchy. The element column[1] is the highest level. Its children should be the immediately following rows that have text in column[2] and so on.
 
I would be glad to see an XSLT or an XQuery solution.
 
Thanks,
Morgan