I have some navigation, which is two levels deep, based on Superfish. It displays the HTML for all nodes of navigation and uses Javascript to show/hide them depending on the ids and classes supplied.
I've got this working except for one thing: there is an id attribute set on the top level <ul> tag, so it reads <ul id="nav">, but this id is also added to all sub-navigation uls when it shouldn't be.
The code I've got so far is as follows. I need to make it so that it only adds 'id="nav"' to the top level ul tag:
Thanks for the prompt reply Dan. I take your point about the id being a class, but it's referenced a lot in the Javascript, so would be opening a small can of worms if changing that.
I just can't get the above code to work. I'm not entirely sure I'm putting it in the right place, but I've tried these and none of them set and ids at all:
Actually, I made a mistake on that last example, I'd moved the wrong code block. It would be nice to be able to edit these posts. Anyhow, I've tried this and it too doesn't seem to set any id:
Add id to first ul in nested navigation list
Hi,
I have some navigation, which is two levels deep, based on Superfish. It displays the HTML for all nodes of navigation and uses Javascript to show/hide them depending on the ids and classes supplied.
I've got this working except for one thing: there is an id attribute set on the top level <ul> tag, so it reads <ul id="nav">, but this id is also added to all sub-navigation uls when it shouldn't be.
The code I've got so far is as follows. I need to make it so that it only adds 'id="nav"' to the top level ul tag:
<?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" 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"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="maxLevelForNav" select="3"/>
<xsl:template match="/">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="drawNodes">
<xsl:param name="parent"/>
<xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
<ul id="nav" class="sf-menu sf-navbar"><xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level <= $maxLevelForNav]">
<li>
<xsl:if test="$currentPage/@id = current()/@id">
<xsl:attribute name="class">current</xsl:attribute>
</xsl:if>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/></a>
<xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and @level <= $maxLevelForNav]) > 0">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Can anyone show me how to do this?
Thanks all...
You could do something like (completely untested)
Although personally, i'd change the ID to a class and let CSS differentiate between
and
Thanks for the prompt reply Dan. I take your point about the id being a class, but it's referenced a lot in the Javascript, so would be opening a small can of worms if changing that.
I just can't get the above code to work. I'm not entirely sure I'm putting it in the right place, but I've tried these and none of them set and ids at all:
Any ideas?
Actually, I made a mistake on that last example, I'd moved the wrong code block. It would be nice to be able to edit these posts. Anyhow, I've tried this and it too doesn't seem to set any id:
Sorted:
I should have been testing for level 1, not 0.
Try this (seems to work on a test umbraco installation)
Dan
is working on a reply...