Navigation - test for child nodes and display not working as expected
Hi There,
I'm having osme issues with my nav macro. I'd like to display all the nodes from the root and test if each node has child nodes and in turn display those.
Your help is much appreciated!
---- Ideal Structure
- main link - main link -- sub link -- sub link - main link -- sub link -- sub link -- sub link - main link -- sub link - main link
Navigation - test for child nodes and display not working as expected
Hi There,
I'm having osme issues with my nav macro. I'd like to display all the nodes from the root and test if each node has child nodes and in turn display those.
Your help is much appreciated!
---- Ideal Structure
- main link
- main link
-- sub link
-- sub link
- main link
-- sub link
-- sub link
-- sub link
- main link
-- sub link
- main link
<?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:param name="parent" select="$currentPage/ancestor-or-self::* [@level=1 and @isDoc]"/>-->
<!-- <xsl:variable name="parent" select="$currentPage/ancestor-or-self::*[@level = 1]" /> -->
<xsl:variable name="parent" select="$currentPage/ancestor-or-self::* [@level='1']" />
<xsl:template match="/">
<xsl:variable name="maxLevel" select="4"/>
<ul class="sf-menu">
<li>
<a href="/">
<xsl:text>Home</xsl:text>
</a>
</li>
<xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevel]">
<!-- Original <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">-->
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
<xsl:variable name="child" select="umbraco.library:GetXmlNodeById(@id)/*[@isDoc]"/>
<xsl:if test="count($child) > 0">
<ul>
<xsl:for-each select="$currentPage [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
Hi Sean,
Here is how you could get youre navigation to display all nodes and child nodes if any is present and where umbracoNaviHide is not set to true.
This is just a way of doing it and from the example am assuming the home or default node will not be displayed.
//fuji
Hi Fuji,
Thanks very much. I added the code you posted into my macro and it worked like a treat. I used a portion of it for the child nodes recursion.
Sean
<?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:param name="parent" select="$currentPage/ancestor-or-self::* [@level=1 and @isDoc]"/>-->
<!-- <xsl:variable name="parent" select="$currentPage/ancestor-or-self::*[@level = 1]" /> -->
<xsl:variable name="parent" select="$currentPage/ancestor-or-self::* [@level='1']" />
<xsl:template match="/">
<xsl:variable name="maxLevel" select="4"/>
<ul class="sf-menu">
<li>
<a href="/">
<xsl:text>Home</xsl:text>
</a>
</li>
<xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevel]">
<!-- Original <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">-->
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
<xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)]">
<ul>
<xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) !='1']">
<li><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
is working on a reply...