Copied to clipboard

Flag this post as spam?

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


  • vaibhav 119 posts 139 karma points
    Mar 10, 2011 @ 09:40
    vaibhav
    0

    Get child nodes according to parents

    Hello all,

    I am very much new to xslt as well as umbraco.

    I want to create xslt file on a hierarchy which looks some thing like this .......

    page 1

           >1-sub page 1

                    >>chid sub page 1

                    >>child sub page 2

           >1-sub page 2

           >1-sub page 3

    page 2

           >2-sub page 1

          >2-sub page 2

           >2-sub page 3

    page 3

           >3-sub page 1

          >3-sub page 2

           >3-sub page 3

    When i click on page 1 or 1-sub page 1 or child sub page 1 or any other child of page 1 ...then it should show thisin side bar.

           >1-sub page 1

                    >>chid sub page 1

                    >>child sub page 2

           >1-sub page 2

           >1-sub page 3

    same should happen with page 2 & page 3 nodes  & there respective child node....

    i was using "List all sub pages from changeble source" ....but problem is that if i have choosen page 1 as source then even if i go to page 2 or page 3 it dosent change .

    So please help me in this.

     

  • Sascha Wolter 615 posts 1101 karma points
    Mar 10, 2011 @ 11:16
    Sascha Wolter
    0

    Assuming that page 1, 2 etc are on level 2 you can do the following:

    <ul>
      <xsl:for-each select="$currentPage/ancestor-or-self::*[@level=2 and @isDoc]/*[@isDoc]">
        <li>
          <a href="{umbraco.library:NiceUrl(@id)}>
            <xsl:value-of select="@nodeName" />
          </a>
          <ul>
            <xsl:for-each select="current()/*[@isDoc]">
              <li>
        <li>
          <a href="{umbraco.library:NiceUrl(@id)}>
            <xsl:value-of select="@nodeName" />
          </a>
          <ul>
            <xsl:for-each select="current()/*[@isDoc]">
              <li>
                <a href="{umbraco.library:NiceUrl(@id)}">
                  <xsl:value-of select="@nodeName" />
                </a>
              </li>
            </xsl:for-each>
          </ul>
        </li>
      </xsl:for-each> 
    </ul>

    This is what happens: on whatever child nodes this code gets executed ($currentPage), the parent node with the level of 2 from it will be selected and from there the for-each statement will work on all the direct child nodes. Since you also want to list the grand children another loop is necessary creating another ul in each li. What you definitely need to do is add some if statemets, e.g. if there aren't any grand children then don't even show the ul.

    Hope that helps,

    Sascha

     

  • vaibhav 119 posts 139 karma points
    Mar 10, 2011 @ 13:27
    vaibhav
    0

    Thanx  Sascha Wolter,

    I just added one codition of if & i worked properly ......

  • Sascha Wolter 615 posts 1101 karma points
    Mar 10, 2011 @ 23:08
    Sascha Wolter
    0

    Great, glad we could fix that so quickly. :)

Please Sign in or register to post replies

Write your reply to:

Draft