Copied to clipboard

Flag this post as spam?

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


  • Frederik T 241 posts 372 karma points
    Sep 01, 2011 @ 14:47
    Frederik T
    0

    Stylable multi-tier menu

    On the site im working on, there is a "About" page about the company, on that page is a menu on the left side, that lists all the nodes, and child nodes of the About page, and that has to remain consistent regardless of where you are of course.

    So i made it, and it worked, but then the designer told me it had to look like this:

    Page 1
    --Page 1a
    --Page 1b
    Page2
    --Page 2a
    --Page 2b
    Page 3
    Page 4

    Meaning that, it had to be displayed like above, every page shown, but the respective children had to be styled differently.

    Before it was just a list, no visual representation that some pages were childnodes of their respective parent etc.

    Not knowing how CSS works (im just a programmer you know) i made it like this (its ugly, very ugly, but im still learning XSLT)

    <xsl:output method="xml" omit-xml-declaration="yes" />

    <xsl:param name="currentPage"/>
    <xsl:variable name="siteRoot" select="umbraco.library:GetXmlNodeById(1082)" />
        
    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul>
    <xsl:for-each select="$siteRoot/descendant::* [@isDoc and string(umbracoNaviHide) != '1']">
    <xsl:choose>
      <xsl:when test="current()/@level = 3">
      <ul>
        <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
            <xsl:attribute name="class">selected</xsl:attribute>
          </xsl:if>
          <xsl:value-of select="@nodeName"/>
        </a>
        </li>
      </ul>
      </xsl:when>
      <xsl:when test="current()/@level = 4">
      <ul>
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
            <xsl:attribute name="class">selected</xsl:attribute>
          </xsl:if>
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
      </ul>
      </xsl:when>
      <xsl:when test="current()/@level = 5">
      <ul>
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
            <xsl:attribute name="class">selected</xsl:attribute>
          </xsl:if>
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
      </ul>
      </xsl:when>
     </xsl:choose>
    </xsl:for-each>
    </ul>
      
    </xsl:template>

    Above you can see that ive made it so specific functions can be adjusted depending on what level the item is in.
    But according to the designer it MUST be like this

    <ul>
      <li> Page1
        <ul>
          <li>Page1a</li>
          <li>Page1b</li>
        </ul>
      </li>
      <li>Page2
        <ul>
          <li>Page 2a</li>
          <li>Page 2b</li>
        </ul>
      </li>
    </ul>

    Ok i think that was the way he put it, said it was a convention and must be like that. Either way, each parent has to be listed, and IF it has child nodes, those has to be displayed as well, but in their respective <ul> for styling purposes.

    Ive tried, but i cant figure out how to do it, anyone have a good idea? doesnt matter if its a quick and dirty solution, the deadline is pretty tight.

  • Frederik T 241 posts 372 karma points
    Sep 01, 2011 @ 16:32
    Frederik T
    0

    Ok, the forums are very unstable now, so it wont let me edit, and i dare not try again, but anyway, ive come up with this solution and i get a feeling that im very close, it comes up with this output:

    <ul>
      <li>
        Page 1
          <ul>
            <li>Page1a
            <li>Page1b
            <li>Page2
            <li>Page2a
          </ul>
      </li>
    </ul>

    I think thats how it is, here is the code:

    <xsl:variable name="siteRoot" select="umbraco.library:GetXmlNodeById(1082)" />
        
    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul>
    <xsl:for-each select="$siteRoot/child::* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
            <xsl:attribute name="class">selected</xsl:attribute>
          </xsl:if>
          <xsl:value-of select="@nodeName"/>
        </a>
        <ul>
          <xsl:for-each select="current()/descendant::* [@isDoc and string(umbracoNaviHide) != '1']">
            <li>
              <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:if test="$currentPage/ancestor-or-self::*/@id = current()/@id">
                  <xsl:attribute name="class">selected</xsl:attribute>
                </xsl:if>
                <xsl:value-of select="@nodeName"/>
              </a>
            </li>
          </xsl:for-each>
        </ul>
      </li>
    </xsl:for-each>
    </ul>
      
    </xsl:template>
Please Sign in or register to post replies

Write your reply to:

Draft