Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • ds 191 posts 223 karma points
    Jul 22, 2011 @ 12:38
    ds
    0

    Display subnodes on menu if there is any?

    By searching on the forum, I have found something similar what I needed. I would like my menu to display subnodes if there any, if not, only parent nodes. but in the following code, I should first click parent page, then it displays subpage. How could I achieve what I need?

    -Page1

       -Page 1.1

       -Page 1.2

    Page2

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
            version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:umb="urn:umbraco.library"
            exclude-result-prefixes="umb">

            <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

            <xsl:param name="currentPage" />
            <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 2]" />
          
              
            <xsl:template match="/">
                    <xsl:if test="$siteRoot/*[@isDoc][not(umbracoNaviHide = 1)]">
                            <ul class="sidebarInnerTopMenuNavSub">
                                    
                                    <!-- Start with children of the site root -->
                                    <xsl:apply-templates select="$siteRoot/*[@isDoc]" />
                            </ul>
                    </xsl:if>
            </xsl:template>
              

            <xsl:template match="*[@isDoc]">
                    <li>
                            <a href="{umb:NiceUrl(@id)}">
                                    <!-- Check if $currentPage is below or at this level -->
                                    <xsl:if test="descendant-or-self::*[@id = $currentPage/@id]">
                                            <xsl:attribute name="class">current</xsl:attribute>
                                    </xsl:if>
                                    <xsl:value-of select="@nodeName" />
                            </a>
                            
                            <!-- If currentPage is below or at this level AND there is at least one visible child -->
                            <xsl:if test="descendant-or-self::*[@id = $currentPage/@id] and *[@isDoc][not(umbracoNaviHide = 1)]">
                                    <ul>
                                            <xsl:apply-templates select="*[@isDoc]" />
                                    </ul>
                            </xsl:if>
                    </li>
            </xsl:template>

            <!-- This automatically hides items with umbracoNaviHide checked -->
            <xsl:template match="*[umbracoNaviHide = 1]" />

    </xsl:stylesheet>

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 22, 2011 @ 13:41
    Fuji Kusaka
    0

    You can do something like that..it will check if there is any child node present and make a loop for other child

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>         
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
       
        <xsl:if test="*[@isDoc]">     
            <xsl:for-each select="*[@isDoc]">
              <li>           
                <a href="{umbraco.library:NiceUrl(@id)}">
                     <xsl:value-of select="@nodeName"/>
                </a>
               </li>
              </
    xsl:for-each>    
       </xsl:if>
      </li>
    </xsl:for-each>

    //Fuji


  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies