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 93679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:22:56+00:00 2026-05-10T23:22:56+00:00

I’m trying to build a multi-level dropdrown CSS menu for a website I’m doing

  • 0

I’m trying to build a multi-level dropdrown CSS menu for a website I’m doing on the umbraco content management system.

I need to build it to have the following structure:

<ul id='nav'>   <li><a href='..'>Page #1</a></li>   <li>     <a href='..'>Page #2</a>     <ul>       <li><a href='..'>Subpage #1</a></li>       <li><a href='..'>Subpage #2</a></li>             </ul>   </li> </ul> 

So now I’m trying to figure out how to do the nesting using XSLT. This is what I have so far:

<xsl:output method='xml' omit-xml-declaration='yes'/>  <xsl:param name='currentPage'/>  <!-- update this variable on how deep your menu should be --> <xsl:variable name='maxLevelForMenu' select='4'/>  <xsl:template match='/'>   <ul id='nav'>     <xsl:call-template name='drawNodes'>         <xsl:with-param         name='parent'         select='$currentPage/ancestor-or-self::node [@level=1]'       />       </xsl:call-template>   </ul> </xsl:template>  <xsl:template name='drawNodes'>   <xsl:param name='parent'/>    <xsl:if test='umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)'>     <xsl:for-each select='$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForMenu]'>        <li>         <a href='{umbraco.library:NiceUrl(@id)}'>           <xsl:value-of select='@nodeName'/>         </a>           <xsl:if test='count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForMenu]) &gt; 0'>              <xsl:call-template name='drawNodes'>                 <xsl:with-param name='parent' select='.'/>               </xsl:call-template>           </xsl:if>        </li>     </xsl:for-each>   </xsl:if> </xsl:template> 

What I can’t seem to figure out is how to check if the first level (here Page #1 and Page #2) has any children, and if they do add the extra <ul> to contain the <li> children.

Anyone out there to point me in the right direction?

  • 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. 2026-05-10T23:22:57+00:00Added an answer on May 10, 2026 at 11:22 pm

    First off, no need pass the a parent parameter around. The context will transport this information.

    Here is the XSL stylesheet that should solve your problem:

    <!-- update this variable on how deep your menu should be --> <xsl:variable name='maxLevelForMenu' select='4'/>  <!--- match the document root ---> <xsl:template match='/root'>   <div id='nav'>     <xsl:call-template name='SubTree' />   </div> </xsl:template>  <!-- this will be called by xsl:apply-templates --> <xsl:template match='node'>   <!-- the node is either protected, or the user is logged on (no need to check for IsProtected twice) -->   <xsl:if test='umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or umbraco.library:IsLoggedOn() = 1'>     <li>       <a href='{umbraco.library:NiceUrl(@id)}'><xsl:value-of select='@nodeName'/></a>       <xsl:call-template name='SubTree' />     </li>   </xsl:if> </xsl:template>  <xsl:template name='SubTree'>   <!-- render sub-tree only if there are any child nodes --->   <xsl:if test='node'>     <ul>       <xsl:apply-templates select='node[data[@alias='umbracoNaviHide'] != '1'][@level &lt;= $maxLevelForMenu]'>         <!-- ensure sorted output of the child nodes --->         <xsl:sort select='@sortOrder' data-type='number' />       </xsl:apply-templates>     </ul>   </xsl:if> </xsl:template> 

    This is the XML I tested it on (I don’t know much about Umbraco, but after looking at some samples I hope I got close to an Umbraco document):

    <root id='-1'>   <node id='1' level='1' sortOrder='1' nodeName='Page #1'>     <data alias='umbracoNaviHide'>0</data>   </node>   <node id='2' level='1' sortOrder='2' nodeName='Page #2'>     <data alias='umbracoNaviHide'>0</data>     <node id='3' level='2' sortOrder='2' nodeName='Subpage #2.2'>       <data alias='umbracoNaviHide'>0</data>     </node>     <node id='4' level='2' sortOrder='1' nodeName='Subpage #2.1'>       <data alias='umbracoNaviHide'>0</data>       <node id='5' level='3' sortOrder='3' nodeName='Subpage #2.1.1'>         <data alias='umbracoNaviHide'>0</data>       </node>     </node>     <node id='6' level='2' sortOrder='3' nodeName='Subpage #2.3'>       <data alias='umbracoNaviHide'>1</data>     </node>   </node>   <node id='7' level='1' sortOrder='3' nodeName='Page #3'>     <data alias='umbracoNaviHide'>1</data>   </node> </root> 

    This is the output:

    <div id='nav'>   <ul>     <li><a href='http://foo/'>Page #1</a></li>     <li><a href='http://foo/'>Page #2</a>       <ul>         <li><a href='http://foo/'>Subpage #2.1</a>           <ul>             <li><a href='http://foo/'>Subpage #2.1.1</a></li>           </ul>         </li>         <li><a href='http://foo/'>Subpage #2.2</a></li>       </ul>     </li>   </ul> </div> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 80k
  • Answers 80k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Besides the problem noted by lc (an hour, a hat)… May 11, 2026 at 4:20 pm
  • Editorial Team
    Editorial Team added an answer You probably also need to specify CallingConvention=CallingConvention.Cdecl since a varargs… May 11, 2026 at 4:20 pm
  • Editorial Team
    Editorial Team added an answer You can use iText#, it's based on a similar Java… May 11, 2026 at 4:20 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.