Copied to clipboard

Flag this post as spam?

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


  • Graeme Paul 44 posts 64 karma points
    Jan 18, 2012 @ 17:27
    Graeme Paul
    0

    help creating a dynamic nav with DLs, DTs, and DDs

    Hello I have a requirement to create a nav using definition lists. Im having some problems a) getting my current nav code to work as is, and b) getting the dt and dd tags working in it. My folder structure is as below, the same navigation has to appear on every page. 

    -London
    --style
    ----red
    ----Blue
    ----Green
    --Diary
    ----Day1
    ----Day2 
    ----Day3

     

    The following code doesnt render the second level child elements on the first page only on the sub pages., i think it has to do with select="./ *[@isDoc. When it does load it loads a li>ul>li> structure, whereas i would like a <dt> for headers and <dd> for the sub links.

    Has anyone got any ideas where I am going wrong. Should i have used a for each instead?

     

    <xsl:template name="ShowMenuItem" match="*">
    <xsl:variable name="isCurrent" select="@id = $currentPage/ancestor-or-self::* /@id" />
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::* [@level=2]" /> <xsl:variable name="mainMenuItems" select="$siteRoot /*[@isDoc and string(umbracoNaviHide) != '1'][not(self::fw_catwalk_review)]" />    <li style="background:#f1f1f1;">
          <a href="{umbraco.library:NiceUrl(@id)}">
            <xsl:value-of select="@nodeName"/>
          </a>
          <xsl:variable name="subPages" select="./ *[@isDoc and string(umbracoNaviHide) != '1']" />
          <xsl:if test="$isCurrent and $subPages">
            <ul class="nav" id="nav-level2" style="padding-left:10px;">
              <xsl:apply-templates select="$subPages" />
            </ul>
          </xsl:if>
        </li>
      </xsl:template>

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 18, 2012 @ 17:56
    Tom Fulton
    0

    Hi,

    The navigation is set to start from your $siteRoot variable, which is set to start at "$currentPage/ancestor-or-self::* [@level=2]" - which means either the current page (if it's level is 2) or it will walk up the tree for the first level 2 ancestor.  So in this case it would not show at all on a level 1 node, since that condition won't be hit.

    I would suggest changing to:

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

    Also, to implement the dl/dt/dd, simply change the markup in your code that is currently writing ul/li

    Hope this helps,
    Tom

  • Graeme Paul 44 posts 64 karma points
    Jan 19, 2012 @ 10:08
    Graeme Paul
    0

    No Luck Tom, this section of the site starts at level2, but even if i change it to level1 its still not lisiting all of the navigation pages in one go, only when i click through.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 19, 2012 @ 13:41
    Tom Fulton
    0

    Hi,

    Can you paste your entire XSLT?  I think there may be an issue with the way you are calling that template.

    -Tom

  • Graeme Paul 44 posts 64 karma points
    Jan 19, 2012 @ 15:34
    Graeme Paul
    0

    Here you go Tom, 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" xmlns:tags="urn:tags" xmlns:pdcalendar="urn:pdcalendar" 
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tags pdcalendar ">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:variable name="level" select="1"/><xsl:param name="currentPage"/>
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::* [@level=2]" />
    <xsl:variable name="mainMenuItems" select="$siteRoot /*[@isDoc and string(umbracoNaviHide) != '1'][not(self::fw_catwalk_review)]" />
    <xsl:template match="/"><!-- start writing XSLT -->
    <div class="fashion_week {$currentPage/ancestor-or-self::* [@level=2]/@nodeName}">
    <header>
    <h1>hello</h1>
    <xsl:apply-templates select="$currentPage/ancestor::blah/fw_location"/>
    </header>
    <div class="left_nav">
    <h3>
    <xsl:value-of select="$currentPage/ancestor-or-self::* [@level=2]/@nodeName"/>
    </h3>
    <xsl:apply-templates select="$mainMenuItems" />
    </div>
    <div class="f_right"><!--top of right col-->
    <xsl:if test ="$currentPage/self::fw_location">
    <img src="{$currentPage/fw_location_hero_img}" alt="{$currentPage/@nodeName}" />
    <div class="street_style f_left">
    <!-- Street  -->
    <h3>Street Style</h3>
    <xsl:apply-templates select="$currentPage/ancestor-or-self::* [@level=2]/fw_style/fw_womens_styles"/>
    </div>
    <div class="quick_gallery f_right">
    <!-- Catwalk Slider here -->
    <xsl:apply-templates select="$currentPage/ancestor-or-self::* [@level=2]/fw_c_review/fw_reviews" mode="location_carousel"/>
    </div>
    </xsl:if>
    <xsl:template name="leftnav" match="*">
    <xsl:variable name="isCurrent" select="@id = $currentPage/ancestor-or-self::* /@id" />
    <li style="background:#f1f1f1;">
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/></a>
    <xsl:variable name="subPages" select="./ *[@isDoc and string(umbracoNaviHide) != '1']" />
    <xsl:if test="$isCurrent and $subPages">
    <ul class="nav" id="nav-level2" style="padding-left:10px;">
    <xsl:apply-templates select="$subPages" />
    </ul>
    </xsl:if>
    </li>
    </xsl:template>
    </xsl:stylesheet>
     
  • Graeme Paul 44 posts 64 karma points
    Jan 20, 2012 @ 13:17
    Graeme Paul
    0

    Ive got my link structure working, just need to convert this to dl, dt and dds. Has anyone done this?

     

     

    <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)">
    <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap][not(self::fw_catwalk_review)]">
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <span>
    <xsl:value-of select="@nodeName"/>
    </span>
    </a>
    <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0">
    <ul>
    <xsl:call-template name="drawNodes">
    <xsl:with-param name="parent" select="."/>
    </xsl:call-template>
    </ul>
    </xsl:if>
    </li>
    </xsl:for-each>
    </xsl:if>
    </xsl:template>

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 20, 2012 @ 14:33
    Tom Fulton
    0

    Hi,

    Glad you got it working!  To change to dl/dt/dd can't you just simply change your <ul> to <dl> etc?

    -Tom

  • Graeme Paul 44 posts 64 karma points
    Jan 20, 2012 @ 16:22
    Graeme Paul
    0

    Tom, i dont think its as simple as that. The problem im facing it the above template renders the imformation 

    <li> <a href="">pigeon</a>
    <ul>
    <li>1</li>
    <li>2</li>  
    <li>3</li>  
    <li>4</li>  
    </ul>
    </li>

     Whereas i want it to render as 

    <dt><a href="">pigeon></a></dt>
    <dd>
    1
    2
    3
    4
    </dd> 

     

     

  • Graeme Paul 44 posts 64 karma points
    Jan 23, 2012 @ 13:38
    Graeme Paul
    0

     

     <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)">
    <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap][not(self::fw_catwalk_review)]">
    <xsl:choose>
    <xsl:when test="@level=3">
    <dt class="tab{position()}">
    <span>
    <xsl:value-of select="@nodeName"/>
    </span>
    </dt>
    </xsl:when>
    <xsl:otherwise>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <span>
    <xsl:value-of select="@nodeName"/>
    </span>
    </a>
    </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0">
    <dd>
    <xsl:call-template name="drawNodes">
    <xsl:with-param name="parent" select="."/>
    </xsl:call-template>
    </dd>
    </xsl:if>
    </xsl:for-each>
    </xsl:if>
    </xsl:template>

    I solved it, see above

     

Please Sign in or register to post replies

Write your reply to:

Draft