I'm now developing left menu for my Umbraco site, and I want it to get all subitems from the current first page in the hierarchy (under the "/"). But when I'm trying to get this node, nothing is returned. Could you please help me with this issue?
Thanks for you reply. Your solution works, but is it gets all nodes under the /. But is it possible to get just the one node that starts the current hierarchy? For example, I have the following URL: /products/universal/current.aspx. How can I get the node "products"?
Getting first node in the menu hierarchy
Hi everyone,
I'm now developing left menu for my Umbraco site, and I want it to get all subitems from the current first page in the hierarchy (under the "/"). But when I'm trying to get this node, nothing is returned. Could you please help me with this issue?
Here is how I'm trying to get the first node:
<xsl:variable name="ancestorNode" select = "$currentPage/ancestor-or-self::node [@level=1]/node"/>
and then using it in the loop:
<xsl:for-each select="$ancestorNode/* [@isDoc and string(umbracoNaviHide) != '1']">
Here is also the full 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"
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="level" select="1"/>
<xsl:variable name="stopLevel" select="/macro/maxDepth"/>
<xsl:variable name="mystartNodeId" select="/macro/startNodeId"/>
<xsl:variable name="cssClass" select="/macro/NavigationCSSClass"/>
<xsl:variable name="cssID" select="/macro/NavigationCSSId"/>
<xsl:variable name="boolImageLink" select="/macro/navImageLink"/>
<xsl:variable name="IDSelectorPrefix" select="/macro/IDPrefix"/>
<xsl:variable name="disableNav" select="/macro/disableNav"/>
<xsl:variable name="ancestorNode" select = "$currentPage/ancestor-or-self::node [@level=1]/node"/>
<xsl:template match="/"><xsl:call-template name="menu">
<xsl:with-param name="level" select="$level"/>
</xsl:call-template></xsl:template><xsl:template name="menu">
<xsl:param name="level"/><ul class="level_{$level}">
<xsl:if test="string($cssClass)">
<xsl:attribute name="class">
<xsl:value-of select="$cssClass"/> level_{$level}
<xsl:if test="$disableNav = 1"> disabled</xsl:if>
</xsl:attribute> </xsl:if>
<xsl:if test="$cssID!= ''">
<xsl:attribute name="id"> <xsl:value-of select="$cssID"/>
</xsl:attribute></xsl:if>
<xsl:if test="count($ancestorNode/* [@isDoc and string(umbracoNaviHide) != '1']) > '0'">
<xsl:for-each select="$ancestorNode/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:if test="$currentPage/@id = current()/@id">
<xsl:attribute name="class">Selected</xsl:attribute>
</xsl:if><xsl:value-of select="@nodeName"/></a>
<xsl:if test="count(current()/* [@isDoc and string(umbracoNaviHide) != '1']) > '0'">
<xsl:call-template name="submenu">
<xsl:with-param name="level" select="$level+1"/>
</xsl:call-template>
</xsl:if>
</li>
</xsl:for-each>
</xsl:if>
</ul>
</xsl:template>
<xsl:template name="submenu">
<xsl:param name="level"/>
<ul class="level_{@level}">
<xsl:for-each select="current()/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
<xsl:if test="count(current()/* [@isDoc and string(umbracoNaviHide) != '1']) > '0'">
<xsl:if test="$currentPage/@id = current()/@id">
<xsl:call-template name="submenu">
<xsl:with-param name="level" select="$level+1"/>
</xsl:call-template>
</xsl:if>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
Thanks in advance
Hi,
Are you using Umbraco 4.5+? If so you should be using * instead of node for the new XML Schema.
Try something like:
<xsl:variable name="ancestorNode" select = "$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>
Hi Tom,
Thanks for you reply. Your solution works, but is it gets all nodes under the /. But is it possible to get just the one node that starts the current hierarchy? For example, I have the following URL: /products/universal/current.aspx. How can I get the node "products"?
Thanks in advance
Hey,
Does products in the above URL have it's own Doc Type?
Rich
Hi,
Yes
Can you post a screen shot of your content structure and which nodes you're trying to display.
Rich
Sure - here it is. For example, when I select "Products" on the top menu, I wand the selected area to appear in the left menu.
Thanks,
Hey,
This should return the 'Product' Node, you will have to change the Doc Type in the XSLT to the name of your product doc type (case sensitive)
<?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:template match="/">
<xsl:variable name="absoluteRoot" select="$currentPage/ancestor-or-self::root" />
<!--Change Doc Type in the next row-->
<xsl:variable name="productNode" select="$absoluteRoot/descendant::* [name() = 'propertyDocType']"/>
<xsl:value-of select="$productNode"/>
</xsl:template>
</xsl:stylesheet>
Hope that helps.
Rich
Alternatively you can use the code I posted but change @level to 2, to have it get the products node in your example.
<xsl:variable name="ancestorNode" select = "$currentPage/ancestor-or-self::* [@isDoc and @level=2]"/>
Agree with Tom, not sure if the original question was how to show ALL level 2 nodes, or just the product node.
Hopefully you can make one of these work depending on your requirement.
Rich
Thanks guys! This - <xsl:variable name="ancestorNode" select = "$currentPage/ancestor-or-self::* [@isDoc and @level=2]"/> - helped me
is working on a reply...