Making menu containing 2 and 3 level Options
sornsen
Posted: Wednesday, December 12, 2007 8:48:32 PM

Rank: Enthusiast

Joined: 10/28/2007
Posts: 17
Location: Roskilde, Denmark
I would like to make a menu containing 2 and 3 level.
I haven't been able to make a code that can handle two levels.
When I have entered Level2-1 then the menu should look like below.

Level2-1
Level3-1
Level3-2
Level3-4
Level2-2
Level2-3

Any idea? Thanks

<xsl:variable name="level" select="3"/>

<xsl:template match="/">

<ul class="navigation">
<xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">

<xsl:attribute name="style">font-weight: bold;</xsl:attribute>
</xsl:if>
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:for-each>
</ul>

</xsl:template>
psterling@homax
Posted: Wednesday, December 12, 2007 10:57:23 PM

Rank: Fanatic

Joined: 10/30/2007
Posts: 215
Location: Bellingham
Martin -

Following is the Umbraco Navigate XSLT with a few changes - 1) formatting the <selected> elements and, 2) I've added in the excludeFromLeftNav Property to the containing Document Type. This is the complete XSLT.

Code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp " ">
]>
<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" indent="yes"/>

  <xsl:param name="currentPage"/>

  <!-- use this to ignore press releases events etc coz they are lister pages-->
  <xsl:variable name="ignoreList" select="string('')"/>

  <xsl:template match="/">

    <xsl:comment>start of FullLeftNavigation.xslt</xsl:comment>
    <xsl:variable name="startNode" select="$currentPage/ancestor-or-self::root/node"/>

      <ul>
        <li>
          <a href="/default.aspx" title="home">
            <xsl:value-of select="umbraco.library:GetDictionaryItem('Home')"/>
            <xsl:text></xsl:text>
          </a>
        </li>
        <xsl:for-each select="$startNode/node[string(./data [@alias='excludeFromLeftNav']) != '1'][string(./data [@alias='umbracoNaviHide']) != '1']">
          <xsl:choose>

            <xsl:when test="count(descendant-or-self::node [@id=$currentPage/@id]) > 0">
              <xsl:call-template name="drawnode">
                <xsl:with-param name="root" select="1"/>
              </xsl:call-template>
            </xsl:when>

            <xsl:otherwise>
              <xsl:call-template name="drawnode">

              </xsl:call-template>
            </xsl:otherwise>

          </xsl:choose>

        </xsl:for-each>
      </ul>

    <xsl:comment> // end of FullLeftNavigation.xslt</xsl:comment>
  </xsl:template>


  <!--
writes out each node item
-->
  <xsl:template name="drawnode">
    <xsl:param name="root"/>


    <xsl:if test="string(./data [@alias='umbracoNaviHide']) != '1'" > <!-- and string(./data [@alias='excludeFromLeftNav']!='1')"> -->

      <li>

        <a href="{umbraco.library:NiceUrl(@id)}" title="{@nodeName}" >
          <xsl:if test="1=$root">
            <xsl:attribute name="class">selected</xsl:attribute>
          </xsl:if>
          <xsl:value-of select="@nodeName"/>
        </a>


        <xsl:if test="count(descendant-or-self::node [@id=$currentPage/@id]) > 0">
          <xsl:if test="node">
            <!-- stop blank uls-->

            <ul>

              <xsl:for-each select="node">
                <xsl:if test="not(contains($ignoreList,./parent::node/@id))">
                  <!--
             <xsl:value-of select="contains($ignoreList,./parent::node/@id)"/>
             <xsl:value-of select="./parent::node/@id"/>
            -->
                  <xsl:choose>

                    <xsl:when test="@id=$currentPage/@id">

                      <xsl:call-template name="drawnode">
                        <xsl:with-param name="root" select="1"/>
                      </xsl:call-template>


                    </xsl:when>

                    <xsl:otherwise>

                      <xsl:call-template name="drawnode">
                      </xsl:call-template>


                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:if>

              </xsl:for-each>
            </ul>

          </xsl:if>
        </xsl:if>


      </li>
    </xsl:if>


  </xsl:template>
</xsl:stylesheet>


Hope this helps,
-Paul

motusconnect.com :: level-2 certified :: MVP 2008/2009
sornsen
Posted: Thursday, December 27, 2007 2:43:40 PM

Rank: Enthusiast

Joined: 10/28/2007
Posts: 17
Location: Roskilde, Denmark
Hi Paul,

I been trying to modify the code you posted.
Your code works like I like it to work, but it starts at Level 1 instead of Level 2.

I have a top menu only containing Level 1 so my left menu should only contain Level 2 and 3.

Something like this:

Level 2
Level 3
Level 3
Level 3
Level 2
Level 2

I haven't worked in XLST before and therefore I can't figure out how I can change the code to like this instead.
Hope you can help me.

Thanks.
psterling@homax
Posted: Thursday, December 27, 2007 6:02:20 PM

Rank: Fanatic

Joined: 10/30/2007
Posts: 215
Location: Bellingham
Martin -

You can accomplish this by setting the "umbracoNaviHide" property to TRUE for your level 1 pages using the above code.

Add a Property called "umbracoNaviHide" to your Document Type used for your level 1 pages and then set the value for each page in the Content node.

There may also be a more elegant way to accomplish this using just the XSLT logic, but it is not apparent to me right now.

-Paul

motusconnect.com :: level-2 certified :: MVP 2008/2009
Berit J
Posted: Friday, January 04, 2008 10:06:58 AM
Rank: Newbie

Joined: 1/4/2008
Posts: 3
Im trying to make the same kind of menustructure, and have found this thread very usefull. Still, I have set the "umbracoNaviHide" property to TRUE for level 1, but it also hides the subnodes, which wasn't exactly the idea.
Probably a very simple solution to this, but I cant seem to figure it out?

Thanx


Berit J
Posted: Monday, January 14, 2008 7:44:51 PM
Rank: Newbie

Joined: 1/4/2008
Posts: 3
Looked at the code again, and managed to remove level 1.

Code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp " ">
]>
<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" indent="yes"/>

  <xsl:param name="currentPage"/>

  <!-- use this to ignore press releases events etc coz they are lister pages-->
  <xsl:variable name="ignoreList" select="string('')"/>

  <xsl:template match="/">

    <xsl:comment>start of FullLeftNavigation.xslt</xsl:comment>
    <xsl:variable name="startNode" select="$currentPage/ancestor-or-self::root/node"/>

      <ul>
              <xsl:for-each select="$startNode/node[string(./data [@alias='excludeFromLeftNav']) != '1'][string(./data [@alias='umbracoNaviHide']) != '1']">
          <xsl:choose>

            <xsl:when test="count(descendant-or-self::node [@id=$currentPage/@id]) > 0">
              <xsl:call-template name="drawnode">
                <xsl:with-param name="root" select="1"/>
              </xsl:call-template>
            </xsl:when>

            <xsl:otherwise>
              <xsl:call-template name="drawnode">

              </xsl:call-template>
            </xsl:otherwise>

          </xsl:choose>

        </xsl:for-each>
      </ul>

    <xsl:comment> // end of FullLeftNavigation.xslt</xsl:comment>
  </xsl:template>


  <!--
writes out each node item
-->
  <xsl:template name="drawnode">
    <xsl:param name="root"/>


    <xsl:if test="string(./data [@alias='umbracoNaviHide']) != '1'" > <!-- and string(./data [@alias='excludeFromLeftNav']!='1')"> -->

     
<xsl:if test="count(ancestor::*) > 2">

        <a href="{umbraco.library:NiceUrl(@id)}" title="{@nodeName}" >
          <xsl:if test="1=$root">
            <xsl:attribute name="class">selected</xsl:attribute>
          </xsl:if>
          <xsl:value-of select="@nodeName"/>
        </a>
</xsl:if>

        <xsl:if test="count(descendant-or-self::node [@id=$currentPage/@id]) > 0">
          <xsl:if test="node">
            <!-- stop blank uls-->

            <ul>

              <xsl:for-each select="node">

                <xsl:if test="not(contains($ignoreList,./parent::node/@id))">
                  <!--
             <xsl:value-of select="contains($ignoreList,./parent::node/@id)"/>
             <xsl:value-of select="./parent::node/@id"/>
            -->
                  <xsl:choose>

                    <xsl:when test="@id=$currentPage/@id">

                      <xsl:call-template name="drawnode">
                        <xsl:with-param name="root" select="1"/>
                      </xsl:call-template>


                    </xsl:when>

                    <xsl:otherwise>

                      <xsl:call-template name="drawnode">
                      </xsl:call-template>


                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:if>
                </xsl:for-each>

            </ul>

          </xsl:if>
        </xsl:if>
 




    </xsl:if>


  </xsl:template>
</xsl:stylesheet>



/Berit
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.