Copied to clipboard

Flag this post as spam?

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


  • Andrei Yazik 24 posts 44 karma points
    Dec 30, 2010 @ 15:52
    Andrei Yazik
    0

    Getting first node in the menu hierarchy

    Hi everyone,

    I'm now developing left menu for my Umbraco site, and I want it to get all subitems from the current first page in the hierarchy (under the "/"). But when I'm trying to get this node, nothing is returned.  Could you please help me with this issue?

    Here is how I'm trying to get the first node:

    <xsl:variable name="ancestorNode" select "$currentPage/ancestor-or-self::node [@level=1]/node"/>

    and then using it in the loop:

    <xsl:for-each select="$ancestorNode/* [@isDoc and string(umbracoNaviHide) != '1']">

    Here is also the full 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" 
    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:param name="level" select="1"/>
      <xsl:variable name="stopLevel" select="/macro/maxDepth"/>
      <xsl:variable name="mystartNodeId" select="/macro/startNodeId"/>
      <xsl:variable name="cssClass" select="/macro/NavigationCSSClass"/>
      <xsl:variable name="cssID" select="/macro/NavigationCSSId"/>
        <xsl:variable name="boolImageLink" select="/macro/navImageLink"/>
       <xsl:variable name="IDSelectorPrefix" select="/macro/IDPrefix"/>
       <xsl:variable name="disableNav" select="/macro/disableNav"/>
      <xsl:variable name="ancestorNode" select "$currentPage/ancestor-or-self::node [@level=1]/node"/>
       <xsl:template match="/"><xsl:call-template name="menu">
         <xsl:with-param name="level" select="$level"/>
         </xsl:call-template></xsl:template><xsl:template name="menu">
       <xsl:param name="level"/><ul class="level_{$level}">
       <xsl:if test="string($cssClass)">    
         <xsl:attribute name="class">      
           <xsl:value-of select="$cssClass"/> level_{$level}      
           <xsl:if test="$disableNav = 1"disabled</xsl:if>    
         </xsl:attribute>  </xsl:if>  
      <xsl:if test="$cssID!= ''">
       <xsl:attribute name="id"<xsl:value-of select="$cssID"/>
       </xsl:attribute></xsl:if>
      <xsl:if test="count($ancestorNode/* [@isDoc and string(umbracoNaviHide) != '1']) &gt; '0'">
         <xsl:for-each select="$ancestorNode/* [@isDoc and string(umbracoNaviHide) != '1']">
           <li>
             <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(current()/* [@isDoc and string(umbracoNaviHide) != '1']) &gt; '0'">
               <xsl:call-template name="submenu">
                 <xsl:with-param name="level" select="$level+1"/>
               </xsl:call-template>
             </xsl:if>
           </li>
         </xsl:for-each>
       </xsl:if>
       </ul>
       </xsl:template>
      
       <xsl:template name="submenu">
         <xsl:param name="level"/>
         <ul class="level_{@level}">
           <xsl:for-each select="current()/* [@isDoc and string(umbracoNaviHide) != '1']">
             <li>
               <href="{umbraco.library:NiceUrl(@id)}">
                 <xsl:value-of select="@nodeName"/>
               </a>
               <xsl:if test="count(current()/* [@isDoc and string(umbracoNaviHide) != '1']) &gt; '0'">
                 <xsl:if test="$currentPage/@id = current()/@id">
                 <xsl:call-template name="submenu">
                   <xsl:with-param name="level" select="$level+1"/>
                 </xsl:call-template>
                   </xsl:if>
               </xsl:if>
             </li>
           </xsl:for-each>
         </ul>
       </xsl:template>
      </xsl:stylesheet>

    Thanks in advance

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 30, 2010 @ 16:58
    Tom Fulton
    0

    Hi,

    Are you using Umbraco 4.5+?  If so you should be using * instead of node for the new XML Schema.

    Try something like:

    <xsl:variable name="ancestorNode" select "$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>

     

  • Andrei Yazik 24 posts 44 karma points
    Jan 03, 2011 @ 10:25
    Andrei Yazik
    0

    Hi Tom,

    Thanks for you reply. Your solution works, but is it gets all nodes under the /. But is it possible to get just the one node that starts the current hierarchy? For example, I have the following URL: /products/universal/current.aspx. How can I get the node "products"?

    Thanks in advance

  • Rich Green 2246 posts 4008 karma points
    Jan 03, 2011 @ 10:42
    Rich Green
    0

    Hey,

    Does products in the above URL have it's own Doc Type?

    Rich

  • Andrei Yazik 24 posts 44 karma points
    Jan 03, 2011 @ 10:44
    Andrei Yazik
    0

    Hi,

    Yes

  • Rich Green 2246 posts 4008 karma points
    Jan 03, 2011 @ 10:48
    Rich Green
    0

    Can you post a screen shot of your content structure and which nodes you're trying to display.

    Rich

  • Andrei Yazik 24 posts 44 karma points
    Jan 03, 2011 @ 10:55
    Andrei Yazik
    0

    Sure - here it is. For example, when I select "Products" on the top menu, I wand the selected area to appear in the left menu.

    Thanks,

  • Rich Green 2246 posts 4008 karma points
    Jan 03, 2011 @ 11:24
    Rich Green
    1

    Hey,

    This should return the 'Product' Node, you will have to change the Doc Type in the XSLT to the name of your product doc type (case sensitive)

    <?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"/>

    <xsl:template match="/">

    <xsl:variable name="absoluteRoot" select="$currentPage/ancestor-or-self::root" />

    <!--Change Doc Type in the next row-->
    <xsl:variable name="productNode" select="$absoluteRoot/descendant::* [name() = 'propertyDocType']"/>

    <xsl:value-of select="$productNode"/> 
      
    </xsl:template>

    </xsl:stylesheet>

    Hope that helps.

    Rich

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 03, 2011 @ 14:02
    Tom Fulton
    0

    Alternatively you can use the code I posted but change @level to 2, to have it get the products node in your example.

    <xsl:variable name="ancestorNode" select = "$currentPage/ancestor-or-self::* [@isDoc and @level=2]"/>
  • Rich Green 2246 posts 4008 karma points
    Jan 03, 2011 @ 16:10
    Rich Green
    0

    Agree with Tom, not sure if the original question was how to show ALL level 2 nodes, or just the product node.

    Hopefully you can make one of these work depending on your requirement.

    Rich

  • Andrei Yazik 24 posts 44 karma points
    Jan 03, 2011 @ 16:58
    Andrei Yazik
    0

    Thanks guys! This - <xsl:variable name="ancestorNode" select = "$currentPage/ancestor-or-self::* [@isDoc and @level=2]"/> - helped me

Please Sign in or register to post replies

Write your reply to:

Draft