As for your posted example, it seems that your missin a ' in your xsl:if statement..
It think it should look like this: <xsl:if test="$currentPage/@nodeName != 'Home'"> (don't know if this RTE removed some formatting when you pasted it).
If you only want the navigation to be shown, when you are at a lvl2 page, you could also write it like this:
do i have up to 4 sub levels and user could add more
i want to be to create a menu to cater for this.
due to lack of knowledge on xslt...i've built 3 xslt files. file gets top nav, file 3 gets level 2 nav file3 gets level 3 nav but level2 dissapears as the current page is no longer level 2.
this menu will go on top of master page.
still working on this....any help much appreciated.
<!-- Create a submenu if this page or an child page is active--> <xsl:if test="./@id = $currentPage/@id or contains($currentPage/@path, concat(',',./@id))"> <xsl:variable name="children" select="umbraco.library:GetXmlNodeById($currentPage/@id)/node"/> <xsl:if test="count($children) > 0"> <xsl:call-template name="drawNodes"> <xsl:with-param name="parent" select="."/> </xsl:call-template> </xsl:if> </xsl:if>
I'm trying to check if the node has children the drawNodes. but the count is always 0...
<xsl:param name="currentPage"/> <xsl:template match="/"> <ul> <!-- draw the home node at level 1 . ignore children --> <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=1][@isDoc and string(umbracoNaviHide) != '1']"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/> </a> </li> </xsl:for-each>
<!-- for each menu item at level 2 --> <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=1]/*[@isDoc and string(umbracoNaviHide) != '1']"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/> </a> <!-- Create a submenu if this page or an child page is active--> <xsl:if test="./@id = $currentPage/@id or contains($currentPage/@path, concat(',',./@id))"> <xsl:call-template name="drawNodes"> <xsl:with-param name="parent" select="."/> </xsl:call-template> </xsl:if> </li> </xsl:for-each> </ul> </xsl:template>
building a sub menu by page version 4.5
Hello everyone.
I'm building a basic navigation.
my structure is as follows:
Home
About
Interests
Skills
Gallery
Work
Sports
what I want to is show the sub pages of About and Gallery. My xslt is shown below.
this works, but i'm building the subpages with this check : xsl:if test="$currentPage/@nodeName != 'Home">
is this the best way to check that the user is not currently on home page. ie, if there on home page dont bother showing sub pages.
<xsl:template match="/">
<xsl:if test="$currentPage/@nodeName != 'Home">
<!-- The fun starts here -->
<ul class="nav">
<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>
</xsl:template>
As for your posted example, it seems that your missin a ' in your xsl:if statement..
It think it should look like this: <xsl:if test="$currentPage/@nodeName != 'Home'"> (don't know if this RTE removed some formatting when you pasted it).
If you only want the navigation to be shown, when you are at a lvl2 page, you could also write it like this:
<xsl:if test="$currentPage/@level='2'">
<xsl:for-each select="$currentPage/*[@isDoc and string(umbracoNavihide) != '1']">
<xsl:value-of select="@nodeName"/>
</xsl:for-each>
</xsl:if>
Let me know if it works, haven't tested it:)
/Peter
Peter, thanks your example above works and is better ....
I am building a forloop but only want it to fire if the node in question has sub nodes.
do you know how i can do this?
>sajid
Hey Sajid,
Have you tried taking a look on the XSLT templates that are in umbraco by default?
I think the sitemap template is what youre looking for.
Hi Neils, please talking again.
my scenario is as follows:
my structure:
Home
About
Skills
Interests
Pigeon Shooting
Gallery
Sports
Footbal
Tennis
Holidays
Italy
do i have up to 4 sub levels and user could add more
i want to be to create a menu to cater for this.
due to lack of knowledge on xslt...i've built 3 xslt files. file gets top nav, file 3 gets level 2 nav file3 gets level 3 nav but level2 dissapears as the current page is no longer level 2.
this menu will go on top of master page.
still working on this....any help much appreciated.
>sajid
Perhaps you can add a count in your for-each that checks if the current node has some descendants..
try:
<xsl:for-each select="$currentPage/*[@isDoc and string(umbracoNavihide) != '1' and count(./* [@isDoc]) > 0]">
Again, haven't tested :)
/Peter
Ah, didn't see your last post, as I was writing a response myself :)
So you only wan't pages of the same level as the current page to be shown?
/Peter
hi Peter, show current page and its menu if has parent show that if has child show that too.
>sajid
Hey Sajid,
Do you want the home item to display at the same level as his children?
I have a xslt script here that displays the tree to the current page and his subpages. And it wil go as deep as you need.
Neils,
Amazing THANKYOU!!!!! it works perfectly...
i cannot something very basic working. and that is to display the xml nodes on the page so i can debug whats going on.
below I've pasted an image gallery xslt in ver4.5:
when i do <xsl:copy-of select="$mediaItems"/> should i expect to see the structure below $mediaItems as i defined this parameter below?
<?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="imageRoot" select="$currentPage/gallery"/>
<xsl:template match="/">
<!-- start writing XSLT -->
<xsl:variable name="mediaItems" select="umbraco.library:GetMedia($imageRoot, true())"/>
<xsl:for-each select="$mediaItems/Folder/Image">
<xsl:variable name="picFile" select="umbracoFile"/>
<xsl:variable name="picW" select="umbracoWidth"/>
<xsl:variable name="picH" select="umbracoHeight"/>
<img>
<xsl:attribute name="src"><xsl:value-of select="$picFile"/></xsl:attribute>
</img>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Neils,
this is my structure using the xslt you kindly posted above:
home
about
skills
sports
Gallery
,when i click on skills then menu changes to:
home
about
skills
sports
Gallery
skills has no children. but the other 2 node have gone down a level
Neils,
when u click on a node with no children, somewhere an empty ul is being written by the xslt producing <ul />, thus moving everything to the left .
looking into the xslt.
Neils, I tried to update your xslt to:
<!-- Create a submenu if this page or an child page is active-->
<xsl:if test="./@id = $currentPage/@id or contains($currentPage/@path, concat(',',./@id))">
<xsl:variable name="children" select="umbraco.library:GetXmlNodeById($currentPage/@id)/node"/>
<xsl:if test="count($children) > 0">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</xsl:if>
</xsl:if>
I'm trying to check if the node has children the drawNodes. but the count is always 0...
>sajid
Hi Neils fixed the problem i noted above: Here' your original xslt with added if statement in bold.
<?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" xmlns:umbraco.contour="urn:umbraco.contour"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.contour ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<ul>
<!-- draw the home node at level 1 . ignore children -->
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=1][@isDoc and string(umbracoNaviHide) != '1']">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:for-each>
<!-- for each menu item at level 2 -->
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=1]/*[@isDoc and string(umbracoNaviHide) != '1']">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
<!-- Create a submenu if this page or an child page is active-->
<xsl:if test="./@id = $currentPage/@id or contains($currentPage/@path, concat(',',./@id))">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</xsl:template>
<!-- draw submenu's -->
<xsl:template name="drawNodes">
<xsl:param name="parent"/>
<xsl:if test="$parent/* [@isDoc and string(umbracoNaviHide) != '1']">
<ul>
<xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
<xsl:if test="./@id = $currentPage/@id or contains($currentPage/@path, concat(',',./@id))">
<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>
Ah cool, thanks for the fix! Good job :)
is working on a reply...