Working With Table of Contents WebPart - MOSS 2007


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>

Up Next
    Ebook Download
    View all
    Learn
    View all