Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Marc 21 posts 40 karma points
    Apr 22, 2011 @ 00:12
    Marc
    0

    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 "&#x00A0;"> ]>
    <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 &lt;= $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 &lt;= $maxLevelForSitemap]) &gt; 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>

     

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 22, 2011 @ 10:59
    Jan Skovgaard
    0

    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 

  • Marc 21 posts 40 karma points
    Apr 22, 2011 @ 18:47
    Marc
    0

    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

  • Kim Andersen 1447 posts 2196 karma points MVP
    Apr 22, 2011 @ 19:24
    Kim Andersen
    1

    Hi Marc

    Could you try changing the line to this:

    <xsl:with-param name="parent" select="umbraco.library:GetXmlNodeById('1010')"/>

    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

  • Marc 21 posts 40 karma points
    Apr 22, 2011 @ 19:30
    Marc
    0

    Yes that line works, thank you so much for all your guys helps

  • Kim Andersen 1447 posts 2196 karma points MVP
    Apr 22, 2011 @ 19:53
    Kim Andersen
    0

    Cool, great to hear Marc :)

    Have a great day!

    /Kim A

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 22, 2011 @ 23:49
    Jan Skovgaard
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft