Copied to clipboard

Flag this post as spam?

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


  • Jordy Vialoux 73 posts 103 karma points
    Nov 10, 2011 @ 23:40
    Jordy Vialoux
    0

    Get Top Level Node

    Hi There,

    I have a tree structure which follows like this:

    Content
         Sub Page

    I'm using a xsl:for-each to list each sub page item in a UL however, I also need to list it's parent.

    Example:

    Content Sub Page Sub Page Sub Page

    Hopefully there is enough information here.

    All suggestions are welcome!

     

  • Andrei Canef 33 posts 84 karma points
    Nov 11, 2011 @ 00:14
    Andrei Canef
    0

    Hi Jordy, and welcome to the forums.

     

    I'm sorry, but I'm not sure I get what you're after. 

     

    Could you provide your code, and more information about what you're trying to achieve? If you're in a for-each loop and looping through the subpages already, then your parent would technically be your $currentPage, unless I'm misunderstanding your question. 

     

     

  • Dan Okkels Brendstrup 101 posts 197 karma points
    Nov 11, 2011 @ 00:20
    Dan Okkels Brendstrup
    2

    So you're aiming for something like a top navigation? Provided that your nodes actually have doctypes like "Content" and "SubPage", then this should do the trick:

    <xsl:template match="/">
      <xsl:variable name="home" select="$currentPage/ancestor-or-self::Content"/>
      <ul>
        <xsl:apply-templates select="$home | $home/SubPage"/>
      </ul>
    </xsl:template>

    <xsl:template match="Content | SubPage">
      <li>
        <xsl:if test="@id = $currentPage/@id">
          <xsl:attribute name="class">selected</xsl:attribute>
        </xsl:if>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:template>

    It applies the same template to both the Content page and its SubPage children, so they will all be listed in the same unordered list. Since I've used "ancestor-or-self" on $currentPage it'll only work if the current page is any of the ones you listed, but you can of course tweak it to work regardless of where you are on the site.

  • Jordy Vialoux 73 posts 103 karma points
    Nov 11, 2011 @ 01:23
    Jordy Vialoux
    0

    Hi Dan,

    Thanks for your response - I tried what you have and it did work however this is my existing code and I'm creating a navigation but it's a tabbed navigation - refer to this for more info :http://unwrongest.com/projects/tabify/

    I need the parent node to also be displayed not just the sub page within the navigation

    Here is my code and hopefully make sense

  • Dan Okkels Brendstrup 101 posts 197 karma points
    Nov 11, 2011 @ 07:37
    Dan Okkels Brendstrup
    2

    Ah, got it. Then this should work:

    <xsl:template match="/">
      <xsl:variable name="home" select="$currentPage/ancestor-or-self::Content"/>
      <xsl:if test="$home[SubPage]">
        <ul>
          <xsl:apply-templates select="$home | $home/SubPage"/>
        </ul>
        <xsl:apply-templates select="$home | $home/SubPage" mode="tabcontent"/>
      </xsl:if>
    </xsl:template>
     
    <xsl:template match="Content">
      <li class="active">
        <a href="#{@urlName}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:template>
     
    <xsl:template match="SubPage">
      <li>
        <a href="#{@urlName}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:template>
     
    <xsl:template match="Content | SubPage" mode="tabcontent">
      <div class="content">
        <xsl:value-of select="bodyText" disable-output-escaping="yes"/>
      </div>
    </xsl:template>
  • Dan Okkels Brendstrup 101 posts 197 karma points
    Nov 16, 2011 @ 14:54
    Dan Okkels Brendstrup
    0

    Oops, just realized that the final template in my example should of course include an @id:

    <xsl:template match="Content | SubPage" mode="tabcontent">
     
    <div class="content" id="{@urlName}">
       
    <xsl:value-of select="bodyText" disable-output-escaping="yes"/>
     
    </div>
    </xsl:template>

    I wish the editor for these forum posts would allow editing of code snippets without messing up all the formatting. Rich text editors and code snippets just don't mix well.

  • Jordy Vialoux 73 posts 103 karma points
    Nov 17, 2011 @ 09:42
    Jordy Vialoux
    0

    Hi Dan,

    Again thanks for all your help - I did get this fixed in the end - a bit of a hack.

    Here is the code

Please Sign in or register to post replies

Write your reply to:

Draft