SIGN UP MEMBER LOGIN:    
ARTICLE

Working With Table of Contents WebPart - MOSS 2007

Posted by Bhushan Gawale Articles | SharePoint May 03, 2010
In this article you will learn how to Work With Table of Contents WebPart - MOSS 2007.
Reader Level:

Hi Everybody,

One of my project requirements was to create sitemap page for the site.

To implement this kind of functionalities MOSS offers you one of great web part known as Table of Contents Webpart.

All you need to do is just configure webpart to get contents from the location and let this web part know that whether to show sites or pages or everything.

You can read about configuring this webpart here and here. But problem with this web part is When you try to use this web part with your Publishing Site and configure webpart to show pages then this web part shows pages from Site's Pages Library but some extra links too!! Example: Documents, Lists, people and groups..etc and of course we don't want to show these kinds of links when you are working with Public facing site.

So to avoid this situation all you need to do is just create a custom xsl style in LevelStyle.xsl and that's it. you are done.

Some basics : Table of Contents webpart uses some xsl files to present data

  • TableOfContentsMain.xsl
  • Header.xsl
  • LevelStyle.xsl

LevelStyle.xsl is used to present each item in Table of Contents WebPart (You can find all these xsl files in Style Library of Site).

So what I have done in this xsl style is, checking url of links which webpart fetches and then compare this url with 'Pages' keyword , as all pages and sites will be of course having url containing 'pages 'word so only those can be allowed and rendered.

because all unwanted links like> Documents, Lists, people and groups were containing link with keyword '_layouts/' so this filtering is done

<xsl:template name="OnlyPagesSites" match="Level[@LevelTemplate= OnlyPagesSites]">
    <xsl:variable name="LevelIndent" select="(number(@LevelNumber)-number(1))*number(14)+number(4)"></xsl:variable>
    <xsl:variable name="LeafIndent" select="$LevelIndent+6"></xsl:variable>
    <xsl:variable name="LeafIndentWithBullet" select="$LevelIndent+14"></xsl:variable>
    <div class="level-section">

           <span class="level-header">
            <xsl:choose>
              <
xsl:when test='string-length(@Path) > 0'>
                <xsl:choose>
                  <
xsl:when test="contains(@Path,'Pages')">
                    <a    href="{cmswrt:EnsureIsAllowedProtocol(string(@Path))}">
                      <xsl:value-of select="@Title"/>
                    </a>
                  </
xsl:when>
                </
xsl:choose>
              </
xsl:when>
              <
xsl:otherwise>
                <
xsl:value-of select="@Title"/>
              </xsl:otherwise>
            </
xsl:choose>
        </
span>

        <xsl:for-each select="child::Item">
          <div class="level-item-pos level-item level-bullet">
            <span id="header">
              <a href="{cmswrt:EnsureIsAllowedProtocol(string(@Path))}">
                <xsl:value-of select="@Title"/>
              </a>
            </
span>
          </
div>
        </
xsl:for-each>

   
</div>
  </xsl:template>

Login to add your contents and source code to this article
share this article :
post comment
 

Bhushan, My manager asked me to show only sub sites in TOC webpart(Not even Libraries,Lists and Discussons headers),i tried with your code but it's not working.Can you please help me out to get only sites names in TOC? Thank you.

Posted by ashok nila Dec 15, 2010
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Become a Sponsor