title: How can I build a tree from a flat XML list using XSLT?
body: <p>i use a minimalist MVC framework, where the <strong>PHP controler</strong> hands the <strong>DOM model</strong> to the <strong>XSLT view</strong> (c.f. <a href="http://okapi.liip.ch/" rel="nofollow noreferrer">okapi</a>).</p>
  
  <p>in order to build a navigation tree, i used nested sets in MYSQL. this way, i end up with a model XML that looks as follows:</p>
  
  <pre><code>&lt;tree&gt;
      &lt;node&gt;
          &lt;name&gt;root&lt;/name&gt;
          &lt;depth&gt;0&lt;/depth&gt;
      &lt;/node&gt;
      &lt;node&gt;
          &lt;name&gt;TELEVISIONS&lt;/name&gt;
          &lt;depth&gt;1&lt;/depth&gt;
      &lt;/node&gt;
      &lt;node&gt;
          &lt;name&gt;TUBE&lt;/name&gt;
          &lt;depth&gt;2&lt;/depth&gt;
      &lt;/node&gt;
      &lt;node&gt;
          &lt;name&gt;LCD&lt;/name&gt;
          &lt;depth&gt;2&lt;/depth&gt;
      &lt;/node&gt;
      &lt;node&gt;
          &lt;name&gt;PLASMA&lt;/name&gt;
          &lt;depth&gt;2&lt;/depth&gt;
      &lt;/node&gt;
      &lt;node&gt;
          &lt;name&gt;PORTABLE ELECTRONICS&lt;/name&gt;
          &lt;depth&gt;1&lt;/depth&gt;
      &lt;/node&gt;
      &lt;node&gt;
          &lt;name&gt;MP3 PLAYERS&lt;/name&gt;
          &lt;depth&gt;2&lt;/depth&gt;
      &lt;/node&gt;
      &lt;node&gt;
          &lt;name&gt;FLASH&lt;/name&gt;
          &lt;depth&gt;3&lt;/depth&gt;
      &lt;/node&gt;
      &lt;node&gt;
          &lt;name&gt;CD PLAYERS&lt;/name&gt;
          &lt;depth&gt;2&lt;/depth&gt;
      &lt;/node&gt;
      &lt;node&gt;
          &lt;name&gt;2 WAY RADIOS&lt;/name&gt;
          &lt;depth&gt;2&lt;/depth&gt;
      &lt;/node&gt;
  &lt;/tree&gt;
  </code></pre>
  
  <p>which represents the following structure:</p>
  
  <ul>
  <li>root
  
  <ul>
  <li>TELEVISIONS
  
  <ul>
  <li>TUBE</li>
  <li>LCD</li>
  <li>PLASMA</li>
  </ul></li>
  <li>PORTABLE ELECTRONICS
  
  <ul>
  <li>MP3 PLAYERS
  
  <ul>
  <li>FLASH</li>
  </ul></li>
  <li>CD PLAYERS</li>
  <li>2 WAY RADIOS</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>How can I convert this flat XML list to a nested HTML list using XSLT?</p>
  
  <p>PS: this is the example tree from the <a href="http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/" rel="nofollow noreferrer">Managing Hierarchical Data in MySQL</a>.</p>