Copied to clipboard

Flag this post as spam?

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


  • jamie 7 posts 27 karma points
    Jul 31, 2012 @ 14:06
    jamie
    0

    Nested Apply_Template Menu Problem

    I have an issue with my menu which is pieced together inside XSLT using apply templates.  The menu is a simple list of horizontal tabs, the submenus (if there are any) slide out on hover using Jquery.

    If the current page is any First (Home) or 2nd level content page  (About Us, Products, Newsletters, Contact Us), the menu works correctly.  If I am on the 3rd level, the sliding menu (3rd level) are non-existent.  Any advice on why it isn't working as expected would be much appreciated! 

    I am also fairly sure there are more succinct ways of achieving what I want, so any advice on how to re-work it optimally would also be mcuh appreciated.

    My basic content structure is (as advised by this post http://www.blogfodder.co.uk/2010/5/13/building-your-first-umbraco-site-from-scratch)

    Home
    - About Us
    - Products
    ---- Product 1
    ---- Product 2
    - Newsletters
    ---- Newsletter 1
    ---- Newsletter 2
    - Contact Us

     

    My XSLT is

    <?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" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:umbraco.contour="urn:umbraco.contour" 
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.contour ">


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

    <xsl:param name="currentPage"/>
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::root/*[@isDoc and @level=1]" />
        
    <xsl:template match="/">
      
      <ul id="nav">
        
        <!-- Run for rootnode and 2nd level nodes (will deal with 3rd level inside the template match)-->
        <xsl:apply-templates select="$siteRoot [@isDoc]" />
        <xsl:apply-templates select="$siteRoot/* [@isDoc and string(umbracoNaviHide) != '1']" />
        
      </ul>

    </xsl:template>
        
    <!-- HOMEPAGE (matches as its the only one at level 1)-->
    <xsl:template match="*[@isDoc]">
      <li>
        <href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName" />
        </a>
      </li>
    </xsl:template>

    <!-- SECOND LEVEL PAGES (matches all at level 2)-->
    <xsl:template match="*[@isDoc and @level = 2]">
      <li>
         <!-- if this node has a child then -->
         <xsl:if test="*[@isDoc and string(umbracoNaviHide) != '1']">
           <xsl:attribute name="class">trigger</xsl:attribute>
         </xsl:if>
         <href="{umbraco.library:NiceUrl(@id)}">
           <xsl:value-of select="@nodeName" />
         </a>
        
         <!-- if this node has a child then (selects 3rd level nodes) -->
         <xsl:if test="*[@isDoc]">
            <ul class="submenu">
                    <xsl:apply-templates select="*[@isDoc]" />
            </ul>
          </xsl:if>            
      </li>
    </xsl:template>

    <!-- THIRD LEVEL PAGES (matches all at level 3)-->
    <xsl:template match="*[@isDoc and @level = 3 and string(umbracoNaviHide) != '1']">
      <li>
        <href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName" />
        </a>
      </li>
    </xsl:template>

    </xsl:stylesheet>

     

    Thanks!

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jul 31, 2012 @ 14:23
    Chriztian Steinmeier
    0

    Hi Jamie,

    Seems a little weird to me at first look - the XSLT should do the same on every level...

    Anything in the jQuery that depends on a class or something that's not set on 3rd level pages (on a master pages)?

    /Chriztian 

  • jamie 7 posts 27 karma points
    Jul 31, 2012 @ 14:32
    jamie
    0

    Hi Chriztian

    I am an idiot.  The output from the XSLT is correct.  It was an incorrect path to my jscript file in my master template causing the problem!  How can I delete this topic?!

    I would however like to know if there is a more succinct method of achieiving the same output - my XSLT feels a little messy...?  This is the first time I've used umbraco and XSLT so any advice appreciated.

    Thanks

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jul 31, 2012 @ 14:44
    Chriztian Steinmeier
    0

    Hi Jamie,

    No worries - that's exactly why we're all here. I can't tell you how many times I've solved an issue by explaining what I *thought* was going on to someone else, only to realize where the culprit was :-)

    There's no reason to delete it either - just make sure to mark your own answer as the solution, so that people with a similar problem can quickly see that the topic has a "solution", so they don't have to dig through the comments...

    I'll post a somewhat cleaned up version of the code, but it's actually pretty good already, compared to some of the othr stuff you'll see here :-)

    /Chriztian

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jul 31, 2012 @ 14:52
    Chriztian Steinmeier
    0

    Hi again,

    This is how I'd write it - should be faily easy to compare yourself - just ask if anything is cryptic :-)

    <?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 = 1]" />
    
        <xsl:template match="/">
            <ul id="nav">
                <xsl:apply-templates select="$siteRoot" />
                <xsl:apply-templates select="$siteRoot/*[@isDoc][not(umbracoNaviHide = 1)]" />
            </ul>
        </xsl:template>
    
        <!-- Generic template for links (matches all levels)-->
        <xsl:template match="*[@isDoc]">
            <li>
                <a href="{umb:NiceUrl(@id)}">
                    <xsl:value-of select="@nodeName" />
                </a>
            </li>
        </xsl:template>
    
        <!-- Special template for 2nd level -->
        <xsl:template match="*[@isDoc][@level = 2]">
            <!-- Grab the child nodes here (if any) -->
            <xsl:variable name="childNodes" select="*[@isDoc][not(umbracoNaviHide = 1)]" />
            <li>
                <!-- Add class if any visible children -->
                <xsl:if test="$childNodes"><xsl:attribute name="class">trigger</xsl:attribute></xsl:if>
                <a href="{umb:NiceUrl(@id)}">
                    <xsl:value-of select="@nodeName" />
                </a>
    
                <xsl:if test="$childNodes">
                    <ul class="submenu">
                        <xsl:apply-templates select="$childNodes" />
                    </ul>
                </xsl:if>
            </li>
        </xsl:template>
    
    </xsl:stylesheet>

    /Chriztian

  • jamie 7 posts 27 karma points
    Jul 31, 2012 @ 16:07
    jamie
    0

    Thanks for your reply.  Much cleaner.  Sometimes you don't see things even though they are staring you in the face! (I obviously didn't need the template to specifically match the 3rd level)

     

Please Sign in or register to post replies

Write your reply to:

Draft