Copied to clipboard

Flag this post as spam?

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


  • Sean 141 posts 179 karma points
    Jun 30, 2012 @ 08:28
    Sean
    0

    Navigation - test for child nodes and display not working as expected

    Hi There,

    I'm having osme issues with my nav macro. I'd like to display all the nodes from the root and test if each node has child nodes and in turn display those.

    Your help is much appreciated!

    ---- Ideal Structure

    - main link
    - main link
    -- sub link
    -- sub link
    - main link
    -- sub link
    -- sub link
    -- sub link
    - main link
    -- sub link
    - main link

     

     

    <?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:param name="parent"  select="$currentPage/ancestor-or-self::* [@level=1 and @isDoc]"/>-->
     <!-- <xsl:variable name="parent" select="$currentPage/ancestor-or-self::*[@level = 1]" /> -->
       <xsl:variable name="parent" select="$currentPage/ancestor-or-self::* [@level='1']" />
      

      <xsl:template match="/">
        <xsl:variable name="maxLevel" select="4"/>


        <ul class="sf-menu">
          <li>
            <a href="/">
              <xsl:text>Home</xsl:text>
            </a>
          </li>
          <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevel]">
            <!-- Original  <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">-->
            <li>
              <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
              </a>
            <xsl:variable name="child" select="umbraco.library:GetXmlNodeById(@id)/*[@isDoc]"/>
              <xsl:if test="count($child) > 0">
                <ul>

                  <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>

            </li>
          </xsl:for-each>


        </ul>
      </xsl:template>

    </xsl:stylesheet>

  • Fuji Kusaka 2203 posts 4220 karma points
    Jun 30, 2012 @ 11:50
    Fuji Kusaka
    1

    Hi Sean,

    Here is how you could get youre navigation to display all nodes and child nodes if any is present and where umbracoNaviHide is not set to true.

     

     

    <xsl:variable name="parent" select="1111"/> <!-- here you can add your parent NodeID -->
    <xsl:variable name="parentNode" select="umbraco.library:GetXmlNodeById($parent)" />
    <ul class="sf-menu">
    <xsl:for-each select="$parentNode/* [@isDoc][not(umbracoNaviHide = 1)]">
    <xsl:element name="li">
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>
    <!-- Test if there is any Child Nodes  -->
    <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)]">
    <ul>
    <xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) !='1']"><xsl:element name="li"><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
    </xsl:element>
    </xsl:for-each>
    </ul>
    </xsl:if>
    </xsl:element>
    </xsl:for-each>
    </ul>

    This is just a way of doing it and from the example am assuming the home or default node will not be displayed.

    //fuji

     

     

     

     

     

     

  • Sean 141 posts 179 karma points
    Jul 01, 2012 @ 10:05
    Sean
    0

    Hi Fuji,

    Thanks very much. I added the code you posted into my macro and it worked like a treat. I used a portion of it for the child nodes recursion.

    Sean

    <?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:param name="parent"  select="$currentPage/ancestor-or-self::* [@level=1 and @isDoc]"/>-->
     <!-- <xsl:variable name="parent" select="$currentPage/ancestor-or-self::*[@level = 1]" /> -->
       <xsl:variable name="parent" select="$currentPage/ancestor-or-self::* [@level='1']" />
      

      <xsl:template match="/">
        <xsl:variable name="maxLevel" select="4"/>


        <ul class="sf-menu">
          <li>
            <a href="/">
              <xsl:text>Home</xsl:text>
            </a>
          </li>
          <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevel]">
            <!-- Original  <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">-->
            <li>
              <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
              </a>
             
              <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)]">
              <ul>
              <xsl:for-each select="./* [@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>
            </li>
          </xsl:for-each>


        </ul>
      </xsl:template>

    </xsl:stylesheet>


Please Sign in or register to post replies

Write your reply to:

Draft