It only works properly when your on the parent/first node, if your under a node then it starts looping thats nodes children, can you guys see anything wrong with my script?
If it works fine on your parent/first (Home?) node, you probably just want to adjust your parent parameter. Do you want it to start at the Homepage? You might try something like:
<xsl:with-param name="parent" select="$currentPage/ancestor::Homepage [@isDoc]"/> <!-- or whatever the alias is of the doctype you want to walk up to -->
<xsl:with-paramname="parent"select="$currentPage/ancestor-or-self::Homepage [@isDoc]"/><!-- or whatever the alias is of the doctype you want to walk up to -->
This will cause the loop to start at the "Content" node, so the first child will be Home, so it should display then. Be careful if you have other nodes at level 1 though as they'll be listed also. You might be better off just listing the Home node manually.
Problems with for-each on nodes
Hello, I am trying to make a simple link list with the pages that has the showInQuickNavigator = 0
here is my code so far:
<?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" exclude-result-prefixes="msxml
umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<ul class="quicknav">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="$currentPage/ancestor::*"/>
</xsl:call-template>
</ul>
</xsl:template>
<xsl:template name="drawNodes">
<xsl:param name="parent"/>
<xsl:for-each select="$parent/* [@isDoc and string(showInQuickNavigator) = '0']">
<li>
<a style="color: #1745B1; font-weight: bold; text-decoration: none;"> » </a>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="siteName"/>
</a>
</li>
<xsl:if test="count(./* [@isDoc and string(showInQuickNavigator) != '1']) > 0">
<li>
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</li>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
It only works properly when your on the parent/first node, if your under a node then it starts looping thats nodes children, can you guys see anything wrong with my script?
Hi,
If it works fine on your parent/first (Home?) node, you probably just want to adjust your parent parameter. Do you want it to start at the Homepage? You might try something like:
<xsl:with-param name="parent" select="$currentPage/ancestor::Homepage [@isDoc]"/> <!-- or whatever the alias is of the doctype you want to walk up to -->
-Tom
With your code above it fixes the dublications I have gotten, now I only need it to also display the Home
my content tree is like this:
Content
- Home
-Sub1
-Sub1.1
-Sub1.2
-Sub1.3
-Sub1.3.1
-Sub2
-Sub3
It displays everthing except the Home
I wan't it to display the Home, got any advice how to do this?
Hi, not really read throught this post but i am pretty sure you are after ancestor-or-self (You need to check that synatx) :) Charlie
SO :
<xsl:with-paramname="parent"select="$currentPage/ancestor-or-self::Homepage [@isDoc]"/><!-- or whatever the alias is of the doctype you want to walk up to -->
Current 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" exclude-result-prefixes="msxml
umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<ul class="quicknav">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="$currentPage/ancestor-or-self::Homepage"/>
</xsl:call-template>
</ul>
</xsl:template>
<xsl:template name="drawNodes">
<xsl:param name="parent"/>
<xsl:for-each select="$parent/* [string(showInQuickNavigator) = '0']">
<li>
<a style="color: #1745B1; font-weight: bold; text-decoration: none;"> » </a>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="siteName"/>
</a>
</li>
<xsl:if test="count(./* [string(showInQuickNavigator) = '0']) > 0">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
It still does not display the Home.
You could change the xpath to:
This will cause the loop to start at the "Content" node, so the first child will be Home, so it should display then. Be careful if you have other nodes at level 1 though as they'll be listed also. You might be better off just listing the Home node manually.
I wan't to add it by node and not hardcode as I want my page to be multi-language.
Current code is still not working:
<?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" exclude-result-prefixes="msxml
umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<ul class="quicknav">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="$currentPage/ancestor::root [@isDoc]"/>
</xsl:call-template>
</ul>
</xsl:template>
<xsl:template name="drawNodes">
<xsl:param name="parent"/>
<xsl:for-each select="$parent/* [@isDoc and string(showInQuickNavigator) = '0']">
<li>
<a style="color: #1745B1; font-weight: bold; text-decoration: none;"> » </a>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="siteName"/>
</a>
</li>
<xsl:if test="count(./* [@isDoc and string(showInQuickNavigator) != '1']) > 0">
<li>
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</li>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I cannot remember the syntax but you need to start of the node where the level= -1. That will be the very root above HOME. Charlie :)
never mind, got it working with:
Just need to change it to ancestor-or-self. thanks everybody.
So this is solution to take from the root:
<xsl:with-param name="parent" select="$currentPage/ancestor-or-self::root"/>
is working on a reply...