Copied to clipboard

Flag this post as spam?

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


  • Marko 2 posts 22 karma points
    Apr 29, 2010 @ 11:11
    Marko
    0

    Xslt menu

    Hello, everyone

    I'm new in xslt so I need some help.

    Here's the problem:

    my main page is having 4 childs (lvl1) each of them having few more childs (lvl2)

    Main
          Page A
                Page A1
                Page A2
                Page A3
                Page A4
          Page B
                Page B1
                Page B2
          Page C
                Page C1
                Page C2
          Page D
                Page D1
                Page D2

    I would like to have menu on my "Main Page" showing only childs of "Page A" page ("Page A1", "Page A2", "Page A3" and "Page A4") and I'm not sure how to set select atribute to include only wanted pages...

     I guess i need to write something like "<xsl:for-each select="$currentPage/ancestor-or-self::node//node [@level=2]/node">" but this one would obviously show childs of "Page B", "Page C" and "Page D" too.

    Thanks in advance.

     

     

     

     

     

     

     

     

  • Tobias Neugebauer 52 posts 93 karma points
    Apr 29, 2010 @ 13:18
    Tobias Neugebauer
    0

    Hi,

    you can check if a node is child of your currently selected node by using somethig like this <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">

    i use a similar approach to display my side navigation up to a certain level see the code below. What i hav done is to create a named-template to be call recursivly until a definend dapth is reached and I only get the links under the current page.

      <xsl:output method="xml" omit-xml-declaration="yes"/>
      <xsl:variable name="level" select="2"/>

      <xsl:param name="currentPage"/>

      <xsl:template match="/">
        <xsl:variable name="parentPage" select="$currentPage/ancestor-or-self::node [@level=$level]" />

        <xsl:if test="count($currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']) > 0">
          <ul>
            <li class="categories">
              <h3>
                mehr in '<xsl:value-of select="$parentPage/@nodeName"/>'
              </h3>

              <xsl:call-template name="renderLinkList">
                <xsl:with-param name="currentPage" select="$currentPage"/>
                <xsl:with-param name="doSubLinks" select="1" />
              </xsl:call-template>

            </li>
          </ul>

        </xsl:if>
      </xsl:template>

      <xsl:template name="renderLinkList">
        <xsl:param name="currentPage" />
        <xsl:param name="doSubLinks" />

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

            <li class="cat-item">
                <a href="{umbraco.library:NiceUrl(@id)}" title="{@nodeName}">
                  <xsl:value-of select="@nodeName"/>
                </a>
              </li>

              <xsl:if test="$doSubLinks = 1 and $currentPage/ancestor-or-self::node/@id = current()/@id">
                <xsl:call-template name="renderLinkList">
                  <xsl:with-param name="currentPage" select="."/>
                </xsl:call-template>
              </xsl:if>

            </xsl:for-each>
          </ul>
        </xsl:if>
      </xsl:template>

    Hope this helps

    Toby

     

  • Marko 2 posts 22 karma points
    Apr 30, 2010 @ 08:17
    Marko
    0

    Thank You alot for Your reply, I've managed to solve my problem now.

Please Sign in or register to post replies

Write your reply to:

Draft