Copied to clipboard

Flag this post as spam?

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


  • Craig O'Mahony 364 posts 918 karma points
    Mar 05, 2015 @ 15:33
    Craig O'Mahony
    0

    Loop through a certain nodes children

    Hi all,

    This is driving me scatty but what I'm trying to acheive is to build a menu based upon the children of a certain node in my tree.

    This is how I'm setting the 'parent' node (ID = 2421 and it's got 2 children)

    <xsl:variable name="homeNode" select="$currentPage/ancestor-or-self::node [@id = 2421]" />

    And this is how I'm trying to loop through the children

    <xsl:for-each select="$homeNode/* [@isDoc ]">
    <li>
    <a class="active" href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="translate(@nodeName, $smallcase, $uppercase)" />
    </a>
    </li>
    </xsl:for-each>

    It looks fine (to me) and I'm getting no errors but it's not falling into the loop. Could someone point out my stupidity please?!?!

    Thanks,

    Craig

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 05, 2015 @ 15:39
    Jan Skovgaard
    100

    Hi Craig

    What version of Umbraco are you doing this on? If it's newer than 4.5 then you should probably use this instead - If you know you need to get the homepage type then you can just call the node type alias like this if I remember correctly. What you're doing above looks like the old schema syntax from before Umbraco 4.5 :)

    <xsl:variable name="homeNode" select="$currentPage/ancestor-or-self::HomePageAlias" />
    

    Hope this helps.

    /Jan

  • Craig O'Mahony 364 posts 918 karma points
    Mar 05, 2015 @ 15:43
    Craig O'Mahony
    0

    You my friend are an internation superstar! That's been killing me for ages!

    Another quick one though, it's possible that in the future I'll have to do this for a separate area in my content tree but both area's will share the same Node Type Alias (which is why I was trying to target the node from it's ID). Do you know of a way to do that?

    Thanks again

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 05, 2015 @ 15:50
    Jan Skovgaard
    0

    Now I'm blushing :D - Glad it helped!

    You can also do it by id if you'd like...then it must look like this

    <xsl:variable name="startNode" select="$currentPage/ancestor-or-self::*[@isDoc and @id='1260']" /> should work...it's from the top of my mind though so there is a chance that the syntax might be slightly off but.

    But what would your structure for the above scenario look like? Because if those two areas are living in each of their sub-branch you should be able to use the same approach as you did for finding the homepage node using the ancestor-or-self axe. Chriztian "I eat XSLT for breakfast 24/7/365" Steinmeier has made a nice visualizer on using axes here http://pimpmyxslt.com/axesviz.aspx - That might be useful.

    /Jan

  • Craig O'Mahony 364 posts 918 karma points
    Mar 05, 2015 @ 16:14
    Craig O'Mahony
    0

    Then's all be on the same level in the tree, I see so what you're saying is that the $currentPage/ancestor-or-self will stop on the first one that it finds?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 05, 2015 @ 16:26
    Jan Skovgaard
    0

    Hi Craig

    Yes that's what it's going to do. So if you need to fetch from 2 different nodes from the same node level then id is the way to go I think.

    /Jan

  • Craig O'Mahony 364 posts 918 karma points
    Mar 05, 2015 @ 16:29
    Craig O'Mahony
    0

    Got it.

    Overthinking the whole thing, great work and great assistance again :)

Please Sign in or register to post replies

Write your reply to:

Draft