XSLT Pull Down Menus Options
tonyforgan
Posted: Monday, March 17, 2008 4:09:37 AM
Rank: Newbie

Joined: 3/17/2008
Posts: 4
Hi,

I am using a slightly modified "Pulldown Menu" XSLT based on the standard templates in Umbraco. I would like some help with excluding certain document types from the generated menu list.

Here is my existing code
Code:

<?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:variable name="level" select="1"/>

      <xsl:template match="/">
            <script type="text/javascript">

                  <xsl:text disable-output-escaping="yes">&lt;!--//--&gt;&lt;![CDATA[//&gt;&lt;!--

sfHover = function() {
      var sfEls = document.getElementById("pulldown_nav").getElementsByTagName("LI");
      for (var i=0; i&lt;sfEls.length; i++) {
            sfEls[i].onmouseover=function() {
                  this.className+=&quot; sfhover&quot;;
            }
            sfEls[i].onmouseout=function() {
                  this.className=this.className.replace(new RegExp(&quot; sfhover\\b&quot;), &quot;&quot;);
            }
      }
}
if (window.attachEvent) window.attachEvent(&quot;onload&quot;, sfHover);

//--&gt;&lt;!]]&gt;</xsl:text>
            </script>
            <xsl:call-template name="DisplayMenuList">
                  <xsl:with-param name="node" select="$currentPage/ancestor-or-self::node [@level = 1]"/>
                  <xsl:with-param name="id" select="string('pulldown_nav')"/>
                  <xsl:with-param name="menuDepth" select="1"/>
            </xsl:call-template>
      </xsl:template>

      <xsl:template name="DisplayMenuList">
            <xsl:param name="node"/>
            <xsl:param name="id"/>
            <xsl:param name="menuDepth"/>
            <xsl:variable name="maxMenuDepth" select="3"/>

            <xsl:if test="$menuDepth &lt; $maxMenuDepth">
                  <ul>
                        <xsl:if test="$id != ''">
                              <xsl:attribute name="id">
                                    <xsl:value-of select="$id"/>
                              </xsl:attribute>
                        </xsl:if>
                        <xsl:for-each select="$node/node [@nodeTypeAlias != 'dtNewsItem' and @nodeTypeAlias != 'dtEmploymentItem' and @level &gt; 0]">
                              <li>
                                    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                                          <xsl:attribute name="class">current</xsl:attribute>
                                    </xsl:if>
                                    <div>
                                          <a href="{umbraco.library:NiceUrl(@id)}">
                                                <xsl:value-of select="@nodeName"/>
                                          </a>
                                    </div>
                                    <xsl:if test="count(./node) &gt; 0">
                                          <xsl:call-template name="DisplayMenuList">
                                                <xsl:with-param name="node" select="."/>
                                                <xsl:with-param name="menuDepth" select="$menuDepth+1"/>
                                          </xsl:call-template>
                                    </xsl:if>
                              </li>
                        </xsl:for-each>
                  </ul>
            </xsl:if>
      </xsl:template>
</xsl:stylesheet>


I am trying to exclude document types with aliases of dtNewsItem and dteEmploymentItem. Currently, the menu generation goes wrong immediately after the Employment section where it is incorrectly adding another <ul> tag and nesting any following menu items instead of skipping the addition of a new <ul> for the employment items.

The employment section top menu contains ONLY employment items (dtEmploymentItem).

Where have I gone wrong?

Thanks in advance.

Tony Forgan
drobar
Posted: Monday, March 17, 2008 2:05:38 PM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,408
Location: KY, USA
Hi, Tony,

You should include the checks for excluded docTypes in your call to the template, rather than within the called template after you've already created the UL element. That way you won't even get the excluded nodes in the first place. Something like this...

Code:

<xsl:call-template name="DisplayMenuList"> 
    <xsl:with-param name="node" select="$currentPage/ancestor-or-self::node [
                                        @level = 1
                                        and @nodeTypeAlias != 'dtNewsItem'
                                        and @nodeTypeAlias != 'dtEmploymentItem'
                                        ]"/> 
    <xsl:with-param name="id" select="string('pulldown_nav')"/> 
    <xsl:with-param name="menuDepth" select="1"/> 
</xsl:call-template> 


cheers,
doug.



MVP 2007-2009 - Official Umbraco Trainer for North America - Percipient Studios
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.