Copied to clipboard

Flag this post as spam?

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


  • Luke Johnson 61 posts 80 karma points
    Jun 15, 2012 @ 19:36
    Luke Johnson
    0

    Multi-level nav with XSLT, displaying children of multiple parents

    I am looking for a way to display links in a sidebar that display each parent node and its children. It is easy enough to display one set of parents and children, but I am having trouble getting multiples to work. This is the output goal:

    <sidebar>

    Parent 1
    -- child 1
    -- child 2
    -- child 3

    Parent 2
    -- child 1
    -- child 2
    -- child 3

    </sidebar>

    I have this working part way, thanks to a solution posted by Sune Jepsen and Thijs Kuipers at http://our.umbraco.org/forum/developers/xslt/15660-multi-level-menu, but it doesn't quite do what I want, and I'm having trouble because I haven't worked with xsl:call-template before.

    The output of the XSLT below is:

    <sidebar>

    Parent 1
    -- child 1
    -- child 2
    -- child 3

    Parent 2 (without any children beneath it)

    </sidebar>

    Here is the XSLT I am using: My guess is that something needs to be changed in the nested xsl:choose clauses, but I'm not sure where to go from here.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
            version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:msxml="urn:schemas-microsoft-com:xslt"
            xmlns:umbraco.library="urn:umbraco.library"
            exclude-result-prefixes="msxml umbraco.library">
    
    
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    
      <xsl:param name="currentPage"/>
    
      <xsl:template match="/">
    
        <xsl:variable name="subMenuTopLevelNodes" select="$currentPage/ancestor-or-self::* [@level = 2]/* [string(umbracoNaviHide) != '1' and @isDoc]"/>
        <xsl:if test="count($subMenuTopLevelNodes) &gt; 0">
          <h1><xsl:value-of select="$currentPage/../@nodeName" /></h1>
            <nav>
              <xsl:call-template name="submenuTree">
                <xsl:with-param name="pageNodes" select="$subMenuTopLevelNodes"/>
              </xsl:call-template>
            </nav>
        </xsl:if>
      </xsl:template>
    
      <xsl:template name="submenuTree">
        <xsl:param name="pageNodes"/>
        <xsl:for-each select="$pageNodes">
    
            <a href="{umbraco.library:NiceUrl(@id)}">
              <xsl:choose>
                <xsl:when test="count(current()/*[string(umbracoNaviHide) != '1' and @isDoc]) &gt; 0">
                  <xsl:choose>
                    <xsl:when test="$currentPage/@level &gt;= current()/@level and @id = $currentPage/ancestor-or-self::*[@level=current()/@level]/@id">
                      <xsl:attribute name="class">show-children</xsl:attribute>
                      <xsl:if test="$currentPage/@id = @id">
                        <xsl:attribute name="class">show-children selected</xsl:attribute>
                      </xsl:if>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:attribute name="class">has-children</xsl:attribute>
                      <xsl:if test="$currentPage/@id = @id">
                        <xsl:attribute name="class">has-children selected</xsl:attribute>
                      </xsl:if>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:if test="$currentPage/@id = @id">
                    <xsl:attribute name="class">selected</xsl:attribute>
                  </xsl:if>
                </xsl:otherwise>
              </xsl:choose>
              <xsl:value-of select="@nodeName"/>
            </a>
    
            <xsl:if test="$currentPage/@level &gt;= current()/@level and @id = $currentPage/ancestor-or-self::*[@level = current()/@level]/@id and count(current()/*[string(umbracoNaviHide) != '1' and @isDoc]) &gt; 0">
                <xsl:call-template name="submenuTree">
                  <xsl:with-param name="pageNodes" select="$currentPage/ancestor-or-self::*[@level = current()/@level]/*[string(umbracoNaviHide) != '1' and @isDoc]"/>
                </xsl:call-template>
            </xsl:if>
        </xsl:for-each>
      </xsl:template>
    </xsl:stylesheet>

    Your assistance is enormously appreciated!

  • Luke Johnson 61 posts 80 karma points
    Jun 15, 2012 @ 19:40
    Luke Johnson
    0

    PS: if it would help to see what I'm working on, the XSLT file above is employed here: http://kaleo.briercrest.ca/about/camp-qwanoes/about-qwanoes/

    If you hover over the "About" tab on the horizontal nav, you'll see that there are two sets of links, one under "Camp Qwanoes" and another under "Briercrest College & Seminary". These two are the parent folders, both under "About". I want to display both sets of child nodes in the side menu when viewing on of the pages in the About section.

  • Kasper Dyrvig 246 posts 379 karma points
    Jun 27, 2012 @ 23:44
    Kasper Dyrvig
    0

    Hi Luke

    I think this link could help you: http://pimpmyxslt.com/axesviz.aspx?contextNode=1066&axis=descendant#screen

    As far I can see you are very close. If I should guess you are missing selecting descendant in subMenuTopLevelNodes... some thing like <xsl:variable name="subMenuTopLevelNodes" select="$currentPage/ancestor-or-self::* [@level = 2]/descendant::* [@isDoc and umbracoNaviHide != 1]"/>

    Hope it works out.

Please Sign in or register to post replies

Write your reply to:

Draft