Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1287 posts 2744 karma points
    Apr 14, 2010 @ 22:55
    Amir Khan
    0

    Improper Nesting of Navigation

    I have the following xslt which is doing it's job to get the appropriate nodes into my navigation, every node above the current node up to the level 1 node, and the nodes at level 1 all the time...

    It's not closing the html tags properly though, it seems like it creates a new <ul>every time it drops a level then closes it at the 1st level inside an <li> tag.

     

    <?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"/>
    <xsl:param name="startLevel" select="1"/>

    <xsl:template match="/">
        <xsl:if test="count($currentPage/ancestor-or-self::node [@level = $startLevel]/node) &gt; 0">
            <ul id="mainNav">
                <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$startLevel]/node [string(data [@alias='umbracoNaviHide']) != '1']">
                    <xsl:call-template name="drawnode">
                        <xsl:with-param name="level" select="1"/>
                    </xsl:call-template>
                </xsl:for-each>
            </ul>
        </xsl:if>
    </xsl:template>

    <xsl:template name="drawnode">
    <xsl:param name="level"/>
        <li>
            <xsl:choose>
                <xsl:when test="@id=$currentPage/@id">
                    <xsl:attribute name="class">level<xsl:value-of select="$level"/>selected</xsl:attribute>
                    </xsl:when>
              
            </xsl:choose>
            <a href="{umbraco.library:NiceUrl(@id)}">
            <xsl:value-of select="@nodeName"/>
            </a>
           
            <xsl:if test="count(descendant-or-self::node [@id=$currentPage/@id]) &gt; 0">
            <ul>
                <xsl:for-each select="node">
                    <xsl:call-template name="drawnode">
                        <xsl:with-param name="level" select="number($level)+1"/>
                    </xsl:call-template>
                </xsl:for-each>
            </ul>
            </xsl:if>
        </li>
    </xsl:template>

    </xsl:stylesheet>

  • Petr Snobelt 923 posts 1535 karma points
    Apr 15, 2010 @ 09:37
    Petr Snobelt
    0

    Try start with change bottom part of code to:

    <xsl:variable name="childs" select="descendant-or-self::node [@id=$currentPage/@id]" />
    <xsl:if test="count($childs) &gt; 0">
    <ul>
                <xsl:for-each select="$childs">

    Petr

     

  • Amir Khan 1287 posts 2744 karma points
    Apr 15, 2010 @ 21:24
    Amir Khan
    0

    For some reason when I try that, it saves the xslt file correctly, but returns a "The connection was reset" error when I try to navigate anywhere. Odd...

Please Sign in or register to post replies

Write your reply to:

Draft