Recursive list of lists in XSL
        Posted  
        
            by Paul Tomblin
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Paul Tomblin
        
        
        
        Published on 2010-02-23T16:32:08Z
        Indexed on 
            2010/06/03
            9:14 UTC
        
        
        Read the original article
        Hit count: 387
        
I have a recursive nodes that I'm trying to set up for jquery-checktree. The nodes look like
foo/bar/ID
       /NAME
       /CHECKED
       bar/ID
          /NAME
          /CHECKED
   /bar/ID
       /NAME
   /bar/ID
       /NAME
       /bar/ID
           /NAME
           /CHECKED
           /bar/ID
               /NAME
               /CHECKED
Where any bar may or may not have one or more bar nodes below it, but any bar will have ID and NAME and might have a CHECKED.
and I want to turn that into
<ul>
  <li><input type="checkbox" name="..." value="..." checked="checked"></input>
      <label for="...">...</label>
      <ul>
        <li><input type="checkbox" name="..." value="..." checked="checked"></input>
          <label for="...">...</label>
        </li>
      </ul>
  <li>....</li>
</ul>
I can get the first level by doing:
    <ul class="tree">
    <xsl:for-each select="/foo/bar/">
        <li><input type="checkbox" name="{ID}" value="{ID}">
            <xsl:if test="CHECKED = 'Y'"><xsl:attribute name="checked">checked</xsl:attribute></xsl:if>
            </input><label for="{ID}"><xsl:value-of select="NAME"/></label>
        </li>
    </xsl:for-each>
    </ul>
But I don't know how to recurse down to the embedded "bar" within the "bar", down to however many levels there might be.
© Stack Overflow or respective owner