Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 622067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:56:39+00:00 2026-05-13T18:56:39+00:00

I have a recursive nodes that I’m trying to set up for jquery-checktree. The

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:56:39+00:00Added an answer on May 13, 2026 at 6:56 pm

    Here’s one way:

    <xsl:template match="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>
            <!-- 
    
                If we have bar children, make a list and recurse
    
            -->
            <xsl:if test="bar">
                <ul>
                    <xsl:apply-templates select="bar"/>
                </ul>
            </xsl:if>
        </li>
    </xsl:template>
    

    This relies on the “automatic” template matching. To ensure the matching takes place, you could either put a <xsl:apply-templates/> inside the <xsl:for-each> loop of your original code, however, you can even improve it all and replace that original code with this template:

    <xsl:template match="/foo">
       <ul class="tree">
           <xsl:apply-templates select="bar"/>
       </ul>
    </xsl:template>
    

    If you want more control, you can also use <xsl:for-each select="bar"> and call a named template (<xsl:template name="some-name">... and <xsl:call-template>) inside the loop. See: http://www.w3.org/TR/xslt#named-templates

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSON string that resembles the following: { foo : bar, id
I have a parser that is effectively a set of recursive functions operating on
I have a recursive function that returns all subtree nodes, given the starting root
I have a recursive model like this: public class Node { public int Id
i have a recursive query like this (note: this is just an example): var
I have a recursive method on the base form that takes in a control
I have a recursive data type like this: template<typename T> struct SomeType { std::map<T,
I am aware that we do have space complexity difference between a recursive and
I have a function that is recursive in C# that i want to edit
I have written a simple depth-first search in Scala with a recursive function like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.