Copied to clipboard

Flag this post as spam?

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


  • Omar 4 posts 25 karma points
    Sep 30, 2011 @ 23:02
    Omar
    0

    Listing Sub Pages when on current page

    I have a structure like this:

     

    Page 1

            > Page 2

                > Page 2a

                > Page 2b

         > Page 3

               > Page 3a

     >Page 4

     

    I need XSLT that will list all sub pages ONLY if I am on that page.

     

    For example if I am on Page 2 this is how the menu structure should look

    > Page 2

                > Page 2a

                > Page 2b

    > Page 3

     >Page 4

    Please help

    Here is what I have so far:

    <?xml version="1.0" encoding="utf-8" ?><xsl:stylesheet        version="1.0"        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"        xmlns:umbraco.library="urn:umbraco.library"        exclude-result-prefixes="umbraco.library">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    <xsl:param name="currentPage" />
    <xsl:variable name="id" select="$currentPage/@id"/>
    <xsl:template match="/">
     <ul>
      <xsl:apply-templates select="$currentPage/*[@isDoc][not(umbracoNaviHide = 1)]" />
     </ul>
    </xsl:template>
    <!-- Template for generic Document Type -->
    <xsl:template match="*[@isDoc]">
    <li>
     <a href="{umbraco.library:NiceUrl(@id)}">
      <xsl:value-of select="@nodeName" />
     </a>


    <xsl:if test="$id=$currentPage/parent::node/@id">
     <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)]">

      <ul>
        <xsl:apply-templates select="*[@isDoc]" />
      </ul>
       </xsl:if>

    </xsl:if>
    </li>
    </xsl:template>
    <!-- No output for these -->
     <xsl:template match="*[umbracoNaviHide = 1]" />
    </xsl:stylesheet>

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 30, 2011 @ 23:51
    Dennis Aaen
    0

    Hi Omar,

    Welcome to the our.umbraco.

    I do not know which version of Umbraco you are using, but if you are using version 4.5 or a newer version something like this shold solve your question.

    <xsl:template match="/">

    <!-- The fun starts here -->
    <ul>
    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:for-each>
    </ul>
    </xsl:template>

     

    This is from the one of the predefined xslt files i Umbraco. The predefined xslt file has the name. List Sub Pages From Current Page.

    From version 4.5 Umbraco comes with a new xml schema. You can read about the difference here:

    http://our.umbraco.org/wiki/reference/xslt/45-xml-schema

    Hope this can helps you to solve your question,

    /Dennis

  • Omar 4 posts 25 karma points
    Oct 01, 2011 @ 00:17
    Omar
    0

    Dennis,

    I must have stated the question wrong. I need to list all Sibling pages AND only the childern of the current page.

     

    If my menu struture looks like this

    Page 1

            > Page 2  <--- PAGE THAT I AM ON

                > Page 2a

                > Page 2b

         > Page 3

               > Page 3a

     >Page 4

     

    Then it should show this:

            > Page 2  <--- PAGE THAT I AM ON

                > Page 2a

                > Page 2b

         > Page 3

        >Page 4

     

    So I want the sub pages of the Current page AND all its siblings

    Thanks

     

  • Omar 4 posts 25 karma points
    Oct 01, 2011 @ 00:35
    Omar
    0

    Here is what i have so far. The problem is the second if statment isnt working right

    <?xml version="1.0" encoding="utf-8" ?><xsl:stylesheet        version="1.0"        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"        xmlns:umbraco.library="urn:umbraco.library"        exclude-result-prefixes="umbraco.library">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    <xsl:param name="currentPage" />

    <xsl:template match="/">
     <ul>
      <xsl:apply-templates select="$currentPage/../* [@isDoc][not(umbracoNaviHide = 1)]" />
     </ul>
    </xsl:template>
    <!-- Template for generic Document Type -->
    <xsl:template match="*[@isDoc]">
    <li>
     <a href="{umbraco.library:NiceUrl(@id)}">
      <xsl:value-of select="@nodeName" />
     </a>


    <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)]">
     <xsl:if test="./../@id = $currentPage/@id">

      <ul>
      
        <xsl:apply-templates select="*[@isDoc]" />
      </ul>
     </xsl:if>
    </xsl:if>
    </li>
    </xsl:template>
    <!-- No output for these -->
     <xsl:template match="*[umbracoNaviHide = 1]" />
    </xsl:stylesheet>

  • Omar 4 posts 25 karma points
    Oct 01, 2011 @ 00:59
    Omar
    1

    I got it to work here is my xslt if anyone want to do the same:

    <?xml version="1.0" encoding="utf-8" ?><xsl:stylesheet        version="1.0"        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"        xmlns:umbraco.library="urn:umbraco.library"        exclude-result-prefixes="umbraco.library">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    <xsl:param name="currentPage" />
    <xsl:variable name="currentPageId" select="$currentPage/@id"/>

    <xsl:template match="/">
     <ul>
      <xsl:apply-templates select="$currentPage/../* [@isDoc][not(umbracoNaviHide = 1)]" />
     </ul>
    </xsl:template>
    <!-- Template for generic Document Type -->
    <xsl:template match="*[@isDoc]">
    <li>
     <a href="{umbraco.library:NiceUrl(@id)}">
      <xsl:value-of select="@nodeName" />
     </a>


    <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)]">
    <xsl:if test="./@id = $currentPageId">

      <ul>
        
        <xsl:apply-templates select="*[@isDoc]" />
      </ul>
    </xsl:if>
    </xsl:if>
    </li>
    </xsl:template>
    <!-- No output for these -->
     <xsl:template match="*[umbracoNaviHide = 1]" />
    </xsl:stylesheet> 

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 01, 2011 @ 01:23
    Dennis Aaen
    0

    Hi Omar,

    I´am glad to hear that you got it to work.

    I have tried to help you find a solution since i write my post. I tested it localhost but I didn´t find the solution before you write that you got it works

    So cool you find the solution :)

    You have the option to select the correct answer by mousing over your own post out of karma points. It will help others to see the post that solved the problem.

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft