Copied to clipboard

Flag this post as spam?

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


  • Alex Campbell 47 posts 69 karma points
    Nov 30, 2010 @ 00:06
    Alex Campbell
    0

    Changing root of Runway Dropdown Nav

    A little help please...

    I am building a site for a client, the site hosts various seperate sports clubs and respective sports. So we have a content structure something like this:

    Content
    - Main Holding Site
    -- Club 01
    --- Club Sport 0101
    -- Club 02
    --- Club Sport 0201
    --- Club Sport 0202

    I am trying to edit the Runway Drow Down navigation XSLT to enable me to have a different parent depending on where you are so a Club and ClubSport could have different navigations. For the sake of explaining this I have created four document types:

    Main
    Club
    ClubSport
    TextPage

    There is only one Main, Clubs can only be directly under Main, ClubSports can only be directly under Clubs, TextPages can be in any on the other three and TextPages can be within TextPages.

    I know that when $currentPage is @level=1 then we are at Main and so that is the parent.

    My problem is that when we're at anything other than @level=1 I could be (say when @level=2) on either a TextPage or Club and I can't figure out how to tell. I'm trying to go through some "whens" to test for the three or so different scenarios:

       <xsl:when test="$currentPage/@level=2">
        <xsl:call-template name="drawNodes">
                       <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@level=2 and @isDoc]"/>
        </xsl:call-template>
       </xsl:when>

    I think I need to be doing something like this:

    <xsl:when test="$currentPage/@level=2 and @$currentPage/docTypeAlias='Club'">

    and I know this must be straightforward but I just can't see it! Aaarggh!

    There's a bit more to this but if I can get this bit then I can probably figure the rest out myself (he says confidently...). Anyone have any much appreciated thoughts?

    Thanks,

    Alex

  • Kim Andersen 1447 posts 2196 karma points MVP
    Nov 30, 2010 @ 00:34
    Kim Andersen
    0

    Hi Alex

    I haven't seen the entire XSLT code that you'd like to change, but if you want to do something when you are on a level 2 node, and the current used document type is equal to Club, instead of this:

    <xsl:when test="$currentPage/@level=2 and @$currentPage/docTypeAlias='Club'">

    I'm pretty sure you can do it like this:

    <xsl:when test="$currentPage/@level=2 and name($currentPage)='Club'">

    /Kim A

  • Alex Campbell 47 posts 69 karma points
    Nov 30, 2010 @ 09:59
    Alex Campbell
    0

    Thanks so much Kim, that works a treat!

    Ok, I have one last issue, that is that when, say, @level>=3, we might be on a text page under a Club or a ClubSport. So, it seems I need to be able to look up the hierarchy and see whether there is a ClubSport, Club or Main above me and choose the lowest level one to be the parent...

    i.e. In this example, TextPage0101' parent would be Club 01 and TextPage010101's parent would be ClubSport0101.

    Content
    - Main Holding Site
    -- Club 01
    --- Club Sport 0101
    ----TextPage010101
    --- TextPage0101
    -- Club 02
    --- Club Sport 0201
    --- Club Sport 0202

    I can't just say $parent/@level = $curentPage/@level - 1 as there could be multiple levels of TextPage...

  • Kim Andersen 1447 posts 2196 karma points MVP
    Nov 30, 2010 @ 21:04
    Kim Andersen
    0

    If you want to know the level of the parent node, you can get it like this:

    <xsl:value-of select="$currentPage/parent::*[@isDoc]/@level" />

    But if you want to do something when a parent node is on a specific level you should be able to do it like this:

    <xsl:if test="$currentPage/parent::*[@isDoc and @level='2']">
    Do something when my parent is on level 2
    </xsl:if>

    Does that help you in what you where trying to do?

    /Kim A

  • Alex Campbell 47 posts 69 karma points
    Nov 30, 2010 @ 21:29
    Alex Campbell
    0

    Hi Kim

    Thanks, but not quite, I'm not being clear. Say the TextPage you are on is on level 6, that TextPage may or may not have a ClubSport ancestor at level 3. If it does then level 3 will be the root of my navigation. If instead it has a Club ancestor at level 2 then that will be the root and lastly if neither of the first two apply then the root will be Main at level 1.

    Make sense?

    Cheers,

    Alex

  • Kim Andersen 1447 posts 2196 karma points MVP
    Nov 30, 2010 @ 23:04
    Kim Andersen
    0

    Ahh okay. Well, let's try.

    I haven't tried exactly what we want to achieve here, so it might not be the most beautiful solution. But first of all, we could make a variable containing some XML with all of the possible node id from the current page. This code should do it:

    <xsl:variable name="nodes">
        <data>      
             <xsl:for-each select="$currentPage/ancestor-or-self::*[@isDoc and (name()= 'Main' or name()='Club' or name()='ClubSport') ] ">
                  <id><xsl:value-of select="@id"/></id>
             </xsl:for-each>  
        </data>
    </xsl:variable>

    The above variable should now contain all of the nodes that has a document type of either 'Main', 'Club' or 'ClubSport'.

    If we only want the node "closest" to the current page we can put this in another variable and use the GetXmlNodeById-extension like this:

    <xsl:variable name="lastId" select="umbraco.library:GetXmlNodeById(msxml:node-set($nodes)/data/id[last()])"/>

    Now you should have the XML of the node closest to the current page with a document type of either 'Main', 'Club' or 'ClubSport'.

    To be sure that I haven't made any mistakes, you could try printing out both the $nodes and the $lastId inside two seperate <textarea>'s. Then we can be sure that we have got the right node's.

    /Kim A

  • Alex Campbell 47 posts 69 karma points
    Nov 30, 2010 @ 23:26
    Alex Campbell
    0

    Kim, you're a genius, but I feel guilty as you've obviously put some work in here and the answer was simpler. In the first section you check for the nodes of particular doctypes like this...

    <xsl:for-each select="$currentPage/ancestor-or-self::*[@isDoc and (name()= 'Main' or name()='Club' or name()='ClubSport') ] ">

    So, what I've done is this

       <xsl:when test="count($currentPage/ancestor-or-self::* [name()='ClubSport']) &gt; 0">...
       <xsl:when test="count($currentPage/ancestor-or-self::* [name()='Club']) &gt; 0">...
       <xsl:when test="count($currentPage/ancestor-or-self::* [name()='Main']) &gt; 0">...

    Which has worked a treat!

    Thank you so much, Xslt is new to me and I'm struggling to get my head around the syntax but it's starting to sink in now!

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 01, 2010 @ 00:08
    Kim Andersen
    0

    Ahh okay, if that's what you wanted to achieve I'm glad it's working for you :)

    Maybe I misunderstood the problem a bit, but great to hear that things worked out the way you wanted.

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft