Navigation block ???

iford's Avatar

iford

07 Feb, 2011 09:18 PM

Im trying to build a navigation block and I have created the index block which looks 2 levels deep (top level + second level) no matter what I try I can only get either the top level folders to display and not the second level folders or vis versa.

<ul>
    <li id="navhom"><a href="/">Home</a></li>
    <xsl:for-each select="//system-folder">
        <xsl:variable name="section"><xsl:value-of select="name"/></xsl:variable>
        <xsl:variable name="section_div">nav<xsl:value-of select="substring($section,0,4)"/></xsl:variable>

        <li id="{$section_div}">
            <xsl:choose>
                <xsl:when test="descendant::system-folder =''">
                    No Sub Folders <xsl:value-of select="name"/>
                </xsl:when>
                <xsl:when test="descendant::system-folder !=''">
                    With Sub Folders <xsl:value-of select="name"/>
                </xsl:when>
            </xsl:choose>
        </li>
    </xsl:for-each>
</ul>

The code above should build the top level navigation wrapped with in an UL with the second level navigation wrapped in their own UL. The second level navigation is written into a hidden div tag until the top level nav is moused over. Of course if there are no secondary level navigation I don't want a hidden div to pop up on mouse over.

Any help on this would be great.. I have a feeling Im just missing something simple.

  1. 1 Posted by Amy on 07 Feb, 2011 10:40 PM

    Amy's Avatar

    It looks like you're using for-each select="//system-folder", which is going to match every single folder (regardless of depth) and set them as a top-level list item. Try switching that to just /system-folder or system-folder instead, without the double slash.

  2. 2 Posted by iford on 07 Feb, 2011 11:07 PM

    iford's Avatar

    Amy thank you but the for-each you are talking about needs to grab all the folders as it is the root for-each to check to see if there are sub folders or not.

    The code below would where I only want to grab the sub folders for a parent folder.

    <xsl:when test="descendant::system-folder !=''">
                    <xsl:value-of select="name"/>
            <ul>
            <xsl:for-each select="system-folder">
            <li><a><xsl:attribute name="href">/<xsl:value-of select="name"/>/index.php</xsl:attribute><xsl:value-of select="display-name"/></a></li>
            </xsl:for-each>
            </ul>
                </xsl:when>
            </xsl:choose>
    

    As it still sits I can get the parent and its sub folders but I can not display any other top level folders if they do not have secondary folders under them.. Again not sure why this is happening as I figured the check for

    <xsl:when test="descendant::system-folder =''">
    

    would catch any top level folder that does not have any secondary folders under it but it does not seem to be working like its suppose to.

  3. 3 Posted by iford on 07 Feb, 2011 11:09 PM

    iford's Avatar

    I guess I can't edit posts..
    That second loop I should have included in the first code sorry about that.

    Full Code

    <ul>
    <li id="navhom"><a href="/">Home</a></li>
    <xsl:for-each select="//system-folder">
        <xsl:variable name="section"><xsl:value-of select="name"/></xsl:variable>
        <xsl:variable name="section_div">nav<xsl:value-of select="substring($section,0,4)"/></xsl:variable>
    
        <li id="{$section_div}">
            <xsl:choose>
                <xsl:when test="descendant::system-folder =''">
                    No Sub Folders <xsl:value-of select="name"/>
                </xsl:when>
                <xsl:when test="descendant::system-folder !=''">
                    <xsl:value-of select="name"/>
            <ul>
            <xsl:for-each select="system-folder">
            <li><a><xsl:attribute name="href">/<xsl:value-of select="name"/>/index.php</xsl:attribute><xsl:value-of select="display-name"/></a></li>
            </xsl:for-each>
            </ul>
                </xsl:when>
            </xsl:choose>
        </li>
    </xsl:for-each>
    </ul>
    
  4. 4 Posted by Amy on 08 Feb, 2011 12:01 AM

    Amy's Avatar

    Try the attached XSLT file. Instead of using for-each loops, I've changed it so that it uses apply-templates, which I find makes the code easier to follow.

    Another thing to watch out for is to make sure all of your folder have a display-name filled in, since the code doesn't currently check for it.

  5. 5 Posted by iford on 08 Feb, 2011 12:04 AM

    iford's Avatar

    Thank you I will take a look at the xslt.

    Correct it does not check for it and I should be a check in for display-name even though I hope I have trained my users well enough that they remember to actually fill it in but then again there will always be one that will forget :)

    Thanks again for your help.

  6. Tim closed this discussion on 21 Jun, 2011 02:06 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac