Copied to clipboard

Flag this post as spam?

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


  • MartinB 411 posts 512 karma points
    Dec 07, 2010 @ 19:14
    MartinB
    0

    Level 0 Navigation (Top level nodes)

    Hi there

    Been searching the forums the last hour looking for an answer to how i get my level 0 (root) nodes liste with xslt for a toplevel navigation menu in the old schema.

    Structure looks like this example:

    - Domain 1
       - Home
       - About
         - Vision
    - Domain 2
       - Home
       - About
         - Vision
    - Domain 3
       - Home
       - About
         - Vision

    I started using the Prototype Navigation xslt, but when i set level=1 i get the nodes below Domain 1. If i set it to 0 i get nothing.

    XSLT:

    <?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"/>

    <!-- Input the documenttype you want here -->
    <!-- Typically '1' for topnavigtaion and '2' for 2nd level -->
    <!-- Use div elements around this macro combined with css -->
    <!-- for styling the navigation -->
    <xsl:variable name="level" select="2"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul>
    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
    <!-- we're under the item - you can do your own styling here -->
    <xsl:attribute name="style">font-weight: bold;</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName"/>
    </a>
    </li>
    </xsl:for-each>
    </ul>

    </xsl:template>

    </xsl:stylesheet>
  • MartinB 411 posts 512 karma points
    Dec 07, 2010 @ 19:14
    MartinB
    0

    Gah, sry for the double post :(

  • MartinB 411 posts 512 karma points
    Dec 07, 2010 @ 19:27
    MartinB
    1

    Got it!

    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/../node [string(data [@alias='umbracoNaviHide']) != '1']">

     

  • Rich Green 2246 posts 4008 karma points
    Dec 07, 2010 @ 19:42
    Rich Green
    0

    Hi Martin,

    Glad you got it sorted!

    In future you might like to structure your site so your pages are all under 'Home' of each site, like this:

     Domain 1
       - Home
       - About
         - Vision
    - Domain 2
       - Home
       - About
         - Vision
    - Domain 3
       - Home
       - About
         - Vision

    Your structure (I imagine) was the reason that the navigation xslt wasn't pulling out all the nodes.

    Rich

  • MartinB 411 posts 512 karma points
    Dec 07, 2010 @ 20:00
    MartinB
    0

    Hi Rich

    With the structure you suggest, how do you go about not hardcoding the Home link since it's on a different level than the other subnodes?

  • Rich Green 2246 posts 4008 karma points
    Dec 07, 2010 @ 20:34
    Rich Green
    0

    Hi Martin,

    This code should work (place it outside of the navigation loop)

    <li>
        <a href="/">
            <xsl:if test="$currentPage/@level=1">
                <xsl:attribute name="class">active</xsl:attribute>
            </xsl:if>
            <xsl:value-of select="$currentPage/ancestor-or-self::node/@nodeName"/>
        </a>
    </li>

    Rich

  • MartinB 411 posts 512 karma points
    Dec 07, 2010 @ 21:27
    MartinB
    0

    Oh, never seen that before.

    I'll bookmark this one and try it out for my next project.

    Thanks for commenting!

  • MartinB 411 posts 512 karma points
    Dec 10, 2010 @ 09:12
    MartinB
    0

    That really didn't work out for me all that well.

    When i change the level variabel to 2 in the original xslt in order to run through the child nodes of the "Homepage" node i dont get the level 1 node (Homepage) with the above example.

    If i leave the level at 1 i don't get the child nodes at all.

    Any advice here?

  • Rich Green 2246 posts 4008 karma points
    Dec 10, 2010 @ 09:50
    Rich Green
    0

    Hi Martin,

    For your version, set the level to 2 and try this code

    <li>
        <a href="/">
            <xsl:if test="$currentPage/@level=1">
                    <xsl:attribute name="class">active</xsl:attribute>
            </xsl:if>
            <xsl:value-of select="$currentPage/ancestor-or-self::root/node/@nodeName"/>
        </a>
    </li>

    Rich

  • MartinB 411 posts 512 karma points
    Dec 10, 2010 @ 22:13
    MartinB
    0

    Hi Rich

    Oh, can do!

    I'll get back to you on that one, thanks :-)

  • MartinB 411 posts 512 karma points
    Dec 13, 2010 @ 09:04
    MartinB
    0

    Hi Rich

    No go, unfortunately. If the level i set to "2", i get the children of the frontpage node, but not the Frontapage node itself.

  • MartinB 411 posts 512 karma points
    Dec 13, 2010 @ 09:08
    MartinB
    0

    Hmm it seems that i'm not using the same XSLT anymore, can't remember when i made the switch :/

    <?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"/>

    <!-- Input the documenttype you want here -->
    <!-- Typically '1' for topnavigtaion and '2' for 2nd level -->
    <!-- Use div elements around this macro combined with css -->
    <!-- for styling the navigation -->
    <xsl:variable name="level" select="1"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul id="menu">
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
    <xsl:attribute name="class">selected</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName"/>
    </a>
    </li>
    </xsl:for-each>
    </ul>

    </xsl:template>

    </xsl:stylesheet>
  • Thijs Kuipers 43 posts 66 karma points
    Dec 13, 2010 @ 14:07
    Thijs Kuipers
    1

    Try the following XPath to select all document nodes under root (with umbracoNaviHide is false):

    $currentPage/ancestor::root/*[@isDoc and string(umbracoNaviHide) != '1']

    This will:

    • Go to the ancestor called root (which is aptly called 'root' and happens to be the root of the Umbraco XML file)
    • Select all direct child nodes of any type (hence the *) that have the property 'isDoc' and do not have a child node called 'umbracoNaviHide' that contains the string value '1'.

    You cannot access the root node using [@level = $level] because it has no property called 'level'. That is why your first XPath $currentPage/ancestor-or-self::*[@level = 1]/../*[@isDoc] did work.

    • Go to the ancestor (or self) on level 1
    • Go to the parent (.. means parent) which happens to be the 'root'
    • Select all nodes with property 'isDoc'
  • MartinB 411 posts 512 karma points
    Dec 13, 2010 @ 20:11
    MartinB
    0

    Hi Thjis

    Cool, i'll give it a go tomorrow!

    Thanks alot for your effort, much appreciated.

  • 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