[xsl] Generating multi-level recursive nested lists??

Subject: [xsl] Generating multi-level recursive nested lists??
From: "Paul Foege" <pfoege@xxxxxxxxxxxxxxxxx>
Date: Mon, 9 Apr 2001 15:28:29 -0700
Hello

I have been struggling with this for the last few days, and I can't seem to
get it to work.  I contacted some other supposed "XML/XSL Experts" and they
couldn't help me.  Any help would be greatly appreciated.


I have the following xml:

<toc>
	<title>Paul's XML Test</title>
	<folder>
	    <foldertitle>Software</foldertitle>

	    <list>
	    	<file>outer 1</file>
	    	<file>outer 2</file>
	    </list>

		<folder>
	    		<foldertitle>Nested</foldertitle>
	    		<list>
	      		<file>nested 1</file>
	      		<file>nested 2</file>
	     		</list>
	   	</folder>

	</folder>

	<folder>
		 <foldertitle>Software2</foldertitle>
			<list>
	    			<file>outer 1b</file>
	    			<file>outer 2b</file>
	   		</list>
	</folder>

</toc>


I am trying to apply an XSL style sheet to produce the following HTML:

	<ul>

	   <li id="foldheader">Software</li>
	   <ul id="foldinglist">
	      <li>outer 1</li>
	      <li>outer 2</li>
	      <li id="foldheader">Nested</li>

		  <ul id="foldinglist">
	         <li>nested 1</li>
	         <li>nested 2</li>
	        </ul>
	   </ul>

	   <li id="foldheader">Software2</li>
	   <ul id="foldinglist">
	      <li>outer 1</li>
	      <li>outer 2</li>
	   </ul>

	</ul>


Here is my XSL:  It messes up on the nesting level of my <LI>s.


<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl";>

  <xsl:template match="/">
    <HTML>
      <BODY>

         <H1><xsl:value-of select="toc/title"/></H1>

		<ol>
        	<xsl:apply-templates select="toc/folder"/>
		</ol>

      </BODY>
    </HTML>
  </xsl:template>


  <xsl:template match="folder">
	 <li id="foldheader"><xsl:value-of select="foldertitle"/></li>
     <xsl:apply-templates />
  </xsl:template>


  <xsl:template match="folder/folder">
  	<ol>
 	  <LI id="foldheader"><xsl:value-of select="foldertitle"/></LI>
      <xsl:apply-templates />
	</ol>
  </xsl:template>


  <xsl:template match="list">
    <ol id="foldinglist">
      <xsl:for-each select="file">
        <li><xsl:apply-templates /></li>
      </xsl:for-each>
    </ol>
  </xsl:template>


  <xsl:template match="text()"><xsl:value-of />
  </xsl:template>

</xsl:stylesheet>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread