I believe you should be able to do it by using the umbraco.library:GetXmlNodeById() extension where you put in the node id of the Level2 a node. You can see the node id by clicking the node in the content tree and go to the "Properties" tab. You can also just hold the mouse pointer over the node and look in the lower left corner of the screen - there the id will also appear.
So what you need to do is change this line
<xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>
Please notice that 1010 should be replaced with the id of your starting node. Since you're starting from a specific node you don't need to do the level check.
Good to hear. Could you please mark Kim's answer as the solution so it will be easier for others to find the solution right away - Just for future reference :-)
Creating a tree navigation start by node id or name
I created a tree navigation using XSLT from a sitemap for the homepage successfully (code below).
Now how do I create a tree navigation that start from some point by node id? for example i have this sitemap
Level1a
--Level 2a
----Level 3a
----Level 3b
--Level 2b
Level 1b
I want to create a tree navigation that just show from Level 2a and below (but not included Level 2b) like this:
Level 2a
--Level 3a
--Level 3b
Which line I have to change from the code that shows whole tree below? Thanks
<?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"/>
<!-- update this variable on how deep your site map should be -->
<xsl:variable name="maxLevelForSitemap" select="40"/>
<xsl:template match="/">
<div id="sitemap">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>
</xsl:call-template>
</div>
</xsl:template>
<xsl:template name="drawNodes">
<xsl:param name="parent"/>
<xsl:if test="umbraco.library:IsProtected($parent/@id,
$parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id,
$parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
<ul id="gray" class="treeview"><xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevelForSitemap]">
<li>
<a style="margin-left:3px;" 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(./* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevelForSitemap]) > 0">
<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>
Hi Marc
I believe you should be able to do it by using the umbraco.library:GetXmlNodeById() extension where you put in the node id of the Level2 a node. You can see the node id by clicking the node in the content tree and go to the "Properties" tab. You can also just hold the mouse pointer over the node and look in the lower left corner of the screen - there the id will also appear.
So what you need to do is change this line
<xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>
To this
<xsl:with-param name="parent" select="umbraco.library:GetXmlNodeById('1010')/ancestor-or-self::* [@isDoc]"/>
Please notice that 1010 should be replaced with the id of your starting node. Since you're starting from a specific node you don't need to do the level check.
Does this work for you?
/Jan
with this line it repeats the sub and copy the sub to the root like this:
Level1a
--Level 2a
----Level 3a
----Level 3b
Level 2a
--Level 3a
--Level 3b
Level 3a
Level 3b
Level 2b
Level 1b
this is test with level 2a as id
Hi Marc
Could you try changing the line to this:
With the same ID as you tried before.
This should give you the child nodes under the node that you specify in the extension. Does that work?
/Kim A
Yes that line works, thank you so much for all your guys helps
Cool, great to hear Marc :)
Have a great day!
/Kim A
Hi Marc
Good to hear. Could you please mark Kim's answer as the solution so it will be easier for others to find the solution right away - Just for future reference :-)
/Jan
is working on a reply...