Hi, I try to write xslt code(Macro) for a side menue that should be developed on our homepage.
My goal is to have a side menue that list only current page and all subpages, so that by clicking on a node the rest of the node dont disappear. but it list all my nodes and not only current page. this is my xslt code:
I guess then you do not need to have the intial for-each, so that you only display the current page on top level? So something like this (no guarantee that it is error-proof):
XSLT and side menue
Hi, I try to write xslt code(Macro) for a side menue that should be developed on our homepage.
My goal is to have a side menue that list only current page and all subpages, so that by clicking on a node the rest of the node dont disappear. but it list all my nodes and not only current page. this is my xslt code:
----
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:param name="self"/>
<xsl:variable name="level" select="1"/>
<xsl:variable name="sublevel" select="2"/>
<xsl:template match="/">
<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(data [@alias='umbracoNaviHide']) != '1'] ">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
<xsl:if test="$currentPage/ancestor-or-self::*/@id=current()/@id and count(current()/descendant::* [@isDoc and string(data [@alias='umbracoNaviHide']) != '1']) > 0">
<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$sublevel]/* [@isDoc and string(data [@alias='umbracoNaviHide']) != '1'] ">
<li>*
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
------
Need help;
Thanks in advance
Hi Mehrdad
Try removing the inner <xsl:if> statement like below:
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:param name="self"/>
<xsl:variable name="level" select="1"/>
<xsl:variable name="sublevel" select="2"/>
<xsl:template match="/">
<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(data [@alias='umbracoNaviHide']) != '1'] ">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
Is this what you're after?
/Jan
Hi,
Thanks for your reply, but it dont work as I want. It only list all the nodes without sub-nodes.
I want something like this if we supouse that we have a page structure like this:
Page 0
Page 1
Sub-page 1
Sub-page 2
Page 2
.............
Page 3
.............
With current page as Page 1 I need to see only
Page 1
Sub-page 1
Sub-page 2
if i cklick on page 1.
Thnaks for any help.
Hi Mehrdad,
I guess then you do not need to have the intial for-each, so that you only display the current page on top level? So something like this (no guarantee that it is error-proof):
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:param name="self"/>
<xsl:variable name="level" select="1"/>
<xsl:variable name="sublevel" select="2"/>
<xsl:template match="/">
<ul>
<li>
<a href="{umbraco.library:NiceUrl($currentPage/@id)}">
<xsl:value-of select="$currentPage/@nodeName"/>
</a>
</li>
<xsl:if test="count($currentPage/descendant::* [@isDoc and string(data [@alias='umbracoNaviHide']) != '1']) > 0">
<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$sublevel]/* [@isDoc and string(data [@alias='umbracoNaviHide']) != '1'] ">
<li>*
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</ul>
</xsl:if>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
Cheers,
Michael
Hi Michael,
It got better but when I click on a sub-page the other sub-page related to same node disappear, like this:
If we assume we have this page and its sub-page then:
Page 1
Sub-page 1
Sub-page 2
If I click on the sub-page 2 the sub-page 1 disappear, I want it remains all the time.
Thanks for your help
Hi Mehrdad,
To make sure I get this correctly;: if you click on sub-page 2, what do you want to see? Only sub-page 1, or als Page 1?
Cheers,
Michael.
Hi, Michael,
If I click on sub-page 2 I want to see Page 1 and all sub-pages again and nothing diisappear from the page tree.
Hi Mehrdad,
I think this should do the work (not tested):
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:param name="self"/>
<xsl:variable name="level" select="1"/>
<xsl:variable name="sublevel" select="2"/>
<xsl:template match="/">
<xsl:variable name="topLevelNode" select="$currentPage/ancestor-or-self::* [@level=$level]"/>
<ul>
<li>
<a href="{umbraco.library:NiceUrl($topLevelNode/@id)}">
<xsl:value-of select="$topLevelNode/@nodeName"/>
</a>
</li>
<xsl:if test="count($topLevelNode/descendant::* [@isDoc and string(data [@alias='umbracoNaviHide']) != '1']) > 0">
<ul>
<xsl:for-each select="$topLevelNode/descendant::* [@level=$sublevel]/* [@isDoc and string(data [@alias='umbracoNaviHide']) != '1'] ">
<li>*
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</ul>
</xsl:if>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
Hi Mike,
it returns the ancestor of page 1 and all other sub-pages that are not related to the page 1.
Thanks
is working on a reply...