Copied to clipboard

Flag this post as spam?

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


  • Andraž 45 posts 65 karma points
    Dec 20, 2009 @ 19:20
    Andraž
    0

    How to add subNavi

    Hello,

    i would really like to ask for help with 2nd level for Navigation. I really tried everything (to my acknowledge) but i keep coming back to Navi.xsl from Creative Website Wizard. I added template to my site: http://www.simprisk.com/home.aspx and now i wanna have down-drop menu. So, i would like to ask where to add this in this code:

     

    <xsl:template match="/">

    <ul id="nav">
    <li class="sub">
    <xsl:for-each select="$currentPage/ancestor::root/node [string(./data [@alias='umbracoNaviHide']) != '1']">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:attribute name="title"><xsl:value-of select="@nodeName" /></xsl:attribute>
                <xsl:value-of select="@nodeName" />
            </a>
        </li>
    </xsl:for-each>

    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=1]/node [string(./data [@alias='umbracoNaviHide']) != '1']">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:attribute name="title"><xsl:value-of select="@nodeName" /></xsl:attribute>
                <xsl:value-of select="@nodeName" />
            </a>
        </li>
    </xsl:for-each>
    </li>
    </ul>


    </xsl:template>

     

    I would really be thankful for any help!

    Thanks, Andraž

  • jonok 297 posts 658 karma points
    Dec 21, 2009 @ 01:25
    jonok
    1

    Hi Andraz, I think I know what you are trying to do, see if this code works for you...

    <?xml version="1.0" encoding="utf-8"?>
    <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="html"/>
        <xsl:param name="currentPage"/>

        <xsl:template match="/">

    <ul id="nav">
    <xsl:for-each select="$currentPage/ancestor::root/node [string(./data [@alias='umbracoNaviHide']) != '1']">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:attribute name="title"><xsl:value-of select="@nodeName" /></xsl:attribute>
                <xsl:value-of select="@nodeName" />
            </a>
        </li>
    </xsl:for-each>

    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=1]/node [string(./data [@alias='umbracoNaviHide']) != '1']">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:attribute name="title"><xsl:value-of select="@nodeName" /></xsl:attribute>
                <xsl:value-of select="@nodeName" />
            </a>
                        <xsl:call-template name="SecondLevelNodes">
                            <xsl:with-param name="parent" select="."/>
                        </xsl:call-template>
        </li>
    </xsl:for-each>
    </ul>

    </xsl:template>

    <xsl:template name="SecondLevelNodes">
            <xsl:param name="parent"/>
            <xsl:if test="count($parent/node[string(data [@alias='umbracoNaviHide']) != '1' ]) > 0">
                <ul class="second-level">
                    <xsl:for-each select="$parent/node[string(data [@alias='umbracoNaviHide']) != '1' ]">
                        <li>
                        <a href="{umbraco.library:NiceUrl(@id)}">
                            <xsl:value-of select="@nodeName"/>
                        </a>
                        </li>
                    </xsl:for-each>
                </ul>
            </xsl:if>
        </xsl:template>

    </xsl:stylesheet>

  • Andraž 45 posts 65 karma points
    Dec 21, 2009 @ 07:22
    Andraž
    0

    Yes, this does the trick.

    Could you just explain me what does this code do: [string(data [@alias='umbracoNaviHide']) != '1' ]) > 0

    I would really like to thank you for your help!

    I wish some day i could pay you back:)

    Thx

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Dec 21, 2009 @ 07:29
    Sebastiaan Janssen
    0

    If you create a new property on your document types with the alias of "umbracoNaviHide" (the type is: true/false, let's name it "Hide in navigation?"), then it gets used here. If the checkbox is set to true, then 

    [string(data [@alias='umbracoNaviHide']) = '1']

    So the item should not be shown in the navigation. During the part of the XSLT that you highlighted, it says: get all of the pages under the current page that do NOT have umbracoNaviHide set to true.

  • Andraž 45 posts 65 karma points
    Dec 21, 2009 @ 11:24
    Andraž
    0

    Thanks,

    for your time, i'ts getting clearer and clearer :)

     

  • Andraž 45 posts 65 karma points
    Dec 23, 2009 @ 09:17
    Andraž
    0

    I would have one more question thought

    I added a class "sub" to <li> for ancestor-or-sefl node. Now, in my page: http://www.simprisk.com/ it's doing great for the first two navigation buttons "domov" and "login" and also for the drop-down menu on "o portalu" button, but the this class applies to "o nas" and "kontaktirajte nas". How can i make thic class work only if there exists subnavigation (drop-down) menu. Should I use some if statment?

     

    This is the code:

    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=1]/node [string(./data [@alias='umbracoNaviHide']) != '1']">
        <li class="sub">
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:attribute name="title"><xsl:value-of select="@nodeName" /></xsl:attribute>
                <xsl:value-of select="@nodeName" />
            </a>
                        <xsl:call-template name="SecondLevelNodes">
                            <xsl:with-param name="parent" select="."/>
                        </xsl:call-template>
        </li>
    </xsl:for-each>

    Tnx,

    Andraž

     

  • jonok 297 posts 658 karma points
    Dec 24, 2009 @ 00:11
    jonok
    0

    Hi Andraz, try this - it has an 'if' statement that checks the child page count and adds the class 'sub' if its > 0.

    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=1]/node [string(./data [@alias='umbracoNaviHide']) != '1']">
        <li>
            <xsl:if test="count(./node[string(data [@alias='umbracoNaviHide']) != '1' ]) > 0">
                <xsl:attribute name="class">sub</xsl:attribute>
            </xsl:if>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:attribute name="title"><xsl:value-of select="@nodeName" /></xsl:attribute>
                <xsl:value-of select="@nodeName" />
            </a>
                        <xsl:call-template name="SecondLevelNodes">
                            <xsl:with-param name="parent" select="."/>
                        </xsl:call-template>
        </li>
    </xsl:for-each>

  • Andraž 45 posts 65 karma points
    Dec 27, 2009 @ 16:47
    Andraž
    0

    Thanks, if"statment" does the trick

    by

  • Andraž 45 posts 65 karma points
    Jan 06, 2010 @ 07:09
    Andraž
    0

    I have one more question.

    I now the basic...but not when it comes to "if" statements. In my site: "http://www.simprisk.com/o-portalu.aspx" I have two sub-pages "Pogoji poslovanja" and "Naročnina" and that's OK. But if i click on "Pogoji poslovanja" i want to show all of the sub-pages that are under parent of "Pogoji poslovanja". So i guess i should use the "if" statement. For now all i have is this:

     

    <?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:template match="/">
       
    <xsl:for-each select="$currentPage/child::node">
    <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
    </li>
    </xsl:for-each>
       
    <xsl:for-each select="$currentPage/following-sibling">
    <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
    </li>
    </xsl:for-each>

    </xsl:template>

    </xsl:stylesheet>

     

    Bye,

     

    Andraz

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Jan 06, 2010 @ 07:18
    Sebastiaan Janssen
    0

    Just doing a

    <xsl:for-each select="$currentPage/node">

    should work..

  • jonok 297 posts 658 karma points
    Jan 06, 2010 @ 09:36
    jonok
    0

    Andraz - try this...

    <!-- set the top level parent node into a variable (you may need to change  the @level number depending on the depth of the startNode from the root node) -->
    <xsl:variable name="startNode" select="$currentPage/ancestor-or-self::node [@level='2']"/>

    <!-- display the top level node (there would be a much cleaner way of doing this without a 'for-each' but I cant remember just now) -->
    <xsl:for-each select="$startNode">
    <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
    </li>
    </xsl:for-each>

    <!-- then loop through the children of the start node -->
    <xsl:for-each select="$startNode/node">
    <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
    </li>
    </xsl:for-each>

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies