[xsl] transform from flat to hierarchical

Subject: [xsl] transform from flat to hierarchical
From: "Ken Tam" <kentam@xxxxxxxxxxxxxxx>
Date: Mon, 27 Nov 2006 00:15:41 -0800
Hi all,

I need to transform from flat and somewhat unstructured XML to a more
structual form. Here is a sample:

<logs>
  <log>a</log>
  <log>sub b</log>
  <log>c</log>
  <log>sub d</log>
  <log>e</log>
  <log>f</log>
  <log>end of d</log>
  <log>g</log>
  <log>end of b</log>
  <log>h</log>
  <log>i</log>
<logs>

into a more structured content with nesting:

<logs>
  <log name="a">
    <log name="b">
      <log name="c">
        <log name="d">
          <log name="e"/>
          <log name="f"/>
        </log>
      </log>
      <log name="g"/>
    </log>
  </log>
  <log name="h"/>
  <log name="i"/>
</logs>

Is this doable by using XSLT/XPATH?. If yes, please include some sample XSLT
code. I've looked at some examples of "flat to hierarchical" transformations
but they are dealt with nestings that are determined by a single node (i.e.
with a "level" attribute) instead of begin-end node pair (as in the "sub
<node>", "end of <node>" pair from above).

Thanks,
kkt

Current Thread