Copied to clipboard

Flag this post as spam?

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


  • Sierra Santiago 33 posts 53 karma points
    Jan 04, 2012 @ 22:18
    Sierra Santiago
    0

    Second Level Navigation

    I have an XSLT file that looks at the main navigation. However, I want it to check to see if there is a second level and set the first item as the main link. For example:

    Home
    -About
    -Services
    --Individuals
    --Business
    -Contact

    Services is listed at the top of my website with Home, About, and Contact but it has a second level (Individuals and Business).  What I want is to have Individuals as the page that pops up when Services is clicked.

    I am EXTREMELY new to Umbraco and I have NEVER worked with XSLT so if someone could help me, that would be wonderful~! Here is my code for the top level navigation:

    <?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"
      exclude-result-prefixes="msxml umbraco.library">

        <xsl:output method="xml" omit-xml-declaration="yes" />
        <xsl:param name="currentPage"/>
        <!-- Input the documenttype you want here -->
        <xsl:variable name="level" select="1"/>
        <xsl:template match="/">
          
     <ul id="navigation">
           <li>
             <href="/">
             <xsl:if test="$currentPage/@id = $currentPage/ancestor-or-self::* [@level=$level]/@id">
                 <xsl:attribute name="id">active</xsl:attribute>
             </xsl:if>
               <span>Home</span>
             </a>
           </li>
          <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
        <href="{umbraco.library:NiceUrl(@id)}">
         <xsl:if test="@id = $currentPage/@id">
            <xsl:attribute name="id">active</xsl:attribute>
          </xsl:if>
          <span><xsl:value-of select="@nodeName"/></span>
        </a>
      </li>
      
      
    </xsl:for-each>
    </ul>
        </xsl:template>

     

  • Sierra Santiago 33 posts 53 karma points
    Jan 04, 2012 @ 22:24
    Sierra Santiago
    0

    Also, I forgot to add, if someone could give me a small hint as to how to access a Textstring property in the XSLT file, that would be great. I need it for this:


    <div>
        <xsl:attribute name="class"><xsl:value-of select="@isDoc and string(icons)"/><xsl:number value="position()" format="1" /></xsl:attribute>
        </div>  

    I want to add a class to the DIV based on the page that is showing. There is already a property called 'icons' for each individual page (Ex: About would be "iconAbout" and Services would be "iconServices", then plus a number which comes up ay-okay). I'm having so much trouble understanding all of this. :( Help is much appreciated~ Thank you ♥

     

  • Rich Green 2246 posts 4008 karma points
    Jan 04, 2012 @ 23:02
    Rich Green
    0

    Hi Sierra,

    Welcome to the forum!

    Do you have a sample of the HTML you are trying to produce?

    Rich

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 04, 2012 @ 23:20
    Kim Andersen
    0

    HI Sierra

    As an answer to your first question about the main navigation, maybe you can try something like this:

    <xsl:variable name="link">
       <xsl:choose>
          <xsl:when test="count(./
    * [@isDoc and string(umbracoNaviHide) != '1']) &gt; 0">
             <xsl:value-of select="umbraco.library:NiceUrl(
    ./* [@isDoc and string(umbracoNaviHide) != '1'][1] /@id)" />
          </xsl:when>
          <xsl:otherwise>
             <xsl:value-of select="
    umbraco.library:NiceUrl(@id)" />
          </xsl:otherwise>
       </xsl:choose>
    </xsl:variable>
    <
    ahref="{$link}">

    Could you try replacing the following part of your code with the above code I provided:

    <ahref="{umbraco.library:NiceUrl(@id)}">

    Does this make any difference?

    /Kim A

  • Sierra Santiago 33 posts 53 karma points
    Jan 05, 2012 @ 02:34
    Sierra Santiago
    0

    Well, it doesn't cause an error so that's a good sign, however, it's still not setting the first second level page as the link. Sorry if I didn't quite explain right. Also, the string(umbracoNaviHide) stuff is from an example XSLT file I pulled. It doesn't actually do anything but it's supposed to look to see if "Hide this Page from Navigation" is checked as yes. I just kept it there in case I want to add this feature later.

    • Home
    • About
    • Services <--This is the link that is being set at the top of my page.
      • Individuals <--This is the page I want to set as the "Service" link so that it shows up rather than an empty ContentPlaceHolder.
      • Business <--However, if THIS were the first page in the list of pages (Evidentally you can sort, cool~!), then this would be set as the "Service" link.
    • Contact


    I hope that makes better sense. Thank you so much for helping me. If you still need the HTML that is to be generated I can write that, although it's pretty much there in the XSLT code.

     

     

     

     

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 05, 2012 @ 08:50
    Kim Andersen
    0

    Hmm... I think the code should work.

    I just tried it out on one of my testsites, and the Service menu link, was changed to the link of the first child under Service.

    But maybe it's because you don't have the umbracoNaviHide-property on your site. Then your code should look like this:

    <xsl:variable name="link">
    <xsl:choose>
    <xsl:when test="count(./* [@isDoc]) &gt; 0">
    <xsl:value-of select="umbraco.library:NiceUrl(./* [@isDoc][1]/@id)" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="umbraco.library:NiceUrl(@id)" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
    <a href="{$link}">

    Does that make a difference?

    /Kim A

  • Sierra Santiago 33 posts 53 karma points
    Jan 05, 2012 @ 14:45
    Sierra Santiago
    0

    It's still not working. Perhaps I just don't have my pages set up right?

    It's all so confusing but I'm sure if I keep playing around with it, I'll get it at some point. Thank you again for your help~ :) 

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 05, 2012 @ 20:54
    Kim Andersen
    0

    That's weird.

    Just to be absolutely sure that we're talking about the same thing. Is the below links the ones that you want to be rendered:

    - About (/about.aspx)

    - Services (/services/individuals.aspx)

    -- Individuals (/services/individuals.aspx)

    -- Business (/services/business.aspx)

     

    Is the above links what you want to achieve?

    /Kim A

  • Sierra Santiago 33 posts 53 karma points
    Jan 06, 2012 @ 15:40
    Sierra Santiago
    0

    Yes~ But I don't think it'll work out. I mean, I'm sure it can but once the business link is clicked, the link active style on Services is no longer there.

    No worries though. I just ended up doing it the long way. I don't want to cause any hassle with anyone in trying to figure it out when there are other ways I can do it. :P

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 06, 2012 @ 22:23
    Kim Andersen
    0

    No worries Sierra. We're here to help out, so just throw your problems in here anytime :)

    You have some problems marking the Services anu link as the active one when Business is the active page?

    /Kim A

  • Sierra Santiago 33 posts 53 karma points
    Jan 09, 2012 @ 20:16
    Sierra Santiago
    0

    Yeah, when one of the other child pages is selected.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 10, 2012 @ 08:37
    Kim Andersen
    0

    Okay, then try changing this part:

    <xsl:iftest="@id = $currentPage/@id">
       <xsl:attributename="id">active</xsl:attribute>
    </xsl:if>

    to something like this:

    <xsl:if test="$currentPage/ancestor-or-self::*[@isDoc]/@id = current()/@id">
    <xsl:attribute name="id">active</xsl:attribute>
    </xsl:if>

    This should put the "active"-id on the topnode, when one of it's childnodes is the current page.

    /Kim A

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 13, 2012 @ 21:24
    Kim Andersen
    0

    Did you solve your problem Sierra?

    /Kim A

  • Sierra Santiago 33 posts 53 karma points
    Jan 13, 2012 @ 23:29
    Sierra Santiago
    0

    Ah, sorry. I've been busy with the new version of the site. I haven't tried the new stuff you sent mainly because something occured with the old version and it pretty much crashed. So I did things differently just because it was becoming too much of a hassle. :/

    Thank you so much for your help though~

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 14, 2012 @ 15:33
    Kim Andersen
    0

    Ahh, okay Sierra. great that yo got things working afterall although you choose another solution :)

    Have a nice day :)

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft