Click here to Skip to main content
15,895,746 members
Articles / Web Development / ASP.NET

SharePoint Page Navigation Web Part

Rate me:
Please Sign up or sign in to vote.
4.56/5 (4 votes)
25 Mar 2009CPOL6 min read 127.3K   540   19  
Web Part for users to drop on their pages for navigation across the site collection.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:rs="urn:schemas-microsoft-com:rowset"
                xmlns:z="#RowsetSchema">

  <xsl:param name="listId" />
  <xsl:param name="listTitle" />
  <xsl:param name="listUrl" />
  <xsl:param name="listImageUrl" />
  <xsl:param name="listEditFormUrl" />
  <xsl:param name="listDefaultViewUrl" />
  <xsl:param name="siteUrl" />

  <!-- Main body template. Sets the Results view (Relevance or date) options -->
  <xsl:template name="dvt_1.body">
    <xsl:param name="Status" />
    <div >
      <table style="font-size:9px;width:100%" cellpadding="5" cellspacing ="0" border="0" >
        <tr>
          <th>Name</th>
          <th>ID</th>
          <th>Requestor</th>
          <th>Status</th>
          <th>Modified</th>
          <th>Created</th>
        </tr>
        <xsl:call-template name="DisplayResults">
          <xsl:with-param name="Status" select="$Status" />
        </xsl:call-template>
      </table>
    </div>
  </xsl:template>

  <!-- This template is called for each result -->
  <xsl:template name="DisplayResults" >
    <xsl:param name="Status" />
    <xsl:for-each select="/xml/rs:data/z:row">
      <xsl:if test="@ows_RFC_x0020_Status = $Status">
        <tr>
          <td>
            <a>
              <xsl:attribute name="href">
                <xsl:value-of select="@ows_EncodedAbsUrl"/>
              </xsl:attribute>
              <xsl:value-of select="@ows_BaseName" />
            </a>
          </td>
          <td>
            <xsl:value-of select="@ows_ID"/>
          </td>
          <td>
            <xsl:value-of select="@ows_Change_x0020_Requestor0"/>
          </td>
          <td>
            <xsl:value-of select="@ows_RFC_x0020_Status"/>
          </td>
          <td>
            <xsl:call-template name="DateFormatter">
              <xsl:with-param name="WholeDate" select="@ows_Modified" />
            </xsl:call-template>
          </td>
          <td>
            <xsl:call-template name="DateFormatter">
              <xsl:with-param name="WholeDate" select="@ows_Created" />
            </xsl:call-template>
          </td>
        </tr>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>

  <!-- Format fields with ;# separator -->
  <xsl:template name="SPFormatSeparatedString">
    <xsl:param name="Value" />
    <xsl:param name="ReturnIndex" />
    <xsl:variable name="val1" select="substring-before($Value,';#')" />
    <xsl:variable name="val2" select="substring-after($Value,';#')" />
    <!-- Printing the Value -->
    <xsl:choose>
      <xsl:when test="$ReturnIndex = 0">
        <xsl:value-of select="$val1"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$val2"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- The size attribute for each result is prepared here -->
  <xsl:template name="DisplaySize">
    <xsl:param name="size" />
    <xsl:if test='string-length($size) &gt; 0'>
      <xsl:if test="number($size) &gt; 0">
        <xsl:choose>
          <xsl:when test="round($size div 1024) &lt; 1">
            <xsl:value-of select="$size" /> Bytes
          </xsl:when>
          <xsl:when test="round($size div (1024 *1024)) &lt; 1">
            <xsl:value-of select="round($size div 1024)" />KB
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="round($size div (1024 * 1024))"/>MB
          </xsl:otherwise>
        </xsl:choose>
      </xsl:if>
    </xsl:if>
  </xsl:template>

  <!-- A generic template to display string with non 0 string length (used for author and lastmodified time -->
  <xsl:template name="DisplayString">
    <xsl:param name="str" />
    <xsl:if test='string-length($str) &gt; 0'>
      <xsl:value-of select="$str" />
    </xsl:if>
  </xsl:template>

  <!-- Date Formatter -->
  <xsl:template name="DateFormatter">
    <xsl:param name="WholeDate" />
    <xsl:variable name="YrMonDat" select="substring-before($WholeDate,' ')" />
    <xsl:variable name="TimeGiven" select="substring-after($WholeDate,' ')" />
    <!--Extracting Date-->
    <xsl:variable name="Year" select="substring-before($YrMonDat,'-')" />
    <xsl:variable name="RemYear" select="substring-after($YrMonDat,'-')" />
    <xsl:variable name="Month" select="substring-before($RemYear,'-')" />
    <xsl:variable name="Day" select="substring-after($RemYear,'-')" />
    <xsl:variable name="MonthName">
      <xsl:choose>
        <xsl:when test="$Month = 1">Jan</xsl:when>
        <xsl:when test="$Month = 2">Feb</xsl:when>
        <xsl:when test="$Month = 3">Mar</xsl:when>
        <xsl:when test="$Month = 4">Apr</xsl:when>
        <xsl:when test="$Month = 5">May</xsl:when>
        <xsl:when test="$Month = 6">Jun</xsl:when>
        <xsl:when test="$Month = 7">Jul</xsl:when>
        <xsl:when test="$Month = 8">Aug</xsl:when>
        <xsl:when test="$Month = 9">Sep</xsl:when>
        <xsl:when test="$Month = 10">Oct</xsl:when>
        <xsl:when test="$Month = 11">Nov</xsl:when>
        <xsl:when test="$Month = 12">Dec</xsl:when>
        <xsl:otherwise>0</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="MonthDisplayNum">
      <xsl:choose>
        <xsl:when test="$Month = 1">1</xsl:when>
        <xsl:when test="$Month = 2">2</xsl:when>
        <xsl:when test="$Month = 3">3</xsl:when>
        <xsl:when test="$Month = 4">4</xsl:when>
        <xsl:when test="$Month = 5">5</xsl:when>
        <xsl:when test="$Month = 6">6</xsl:when>
        <xsl:when test="$Month = 7">7</xsl:when>
        <xsl:when test="$Month = 8">8</xsl:when>
        <xsl:when test="$Month = 9">9</xsl:when>
        <xsl:when test="$Month = 10">10</xsl:when>
        <xsl:when test="$Month = 11">11</xsl:when>
        <xsl:when test="$Month = 12">12</xsl:when>
        <xsl:otherwise>0</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <!--Extracting Time-->
    <xsl:variable name="MilHour" select="substring-before($TimeGiven,':')" />
    <xsl:variable name="RemHour" select="substring-after($TimeGiven,':')" />
    <xsl:variable name="Min" select="substring-before($RemHour,':')" />
    <xsl:variable name="Hour">
      <xsl:choose>
        <xsl:when test="$MilHour &gt; 12">
          <xsl:value-of select="$MilHour - 12"/>
        </xsl:when>
        <xsl:when test="$MilHour = 0">
          12
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$MilHour"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="HourExt">
      <xsl:choose>
        <xsl:when test="$MilHour &gt; 12">
          PM
        </xsl:when>
        <xsl:otherwise>
          AM
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <!-- Printing the Value -->
    <xsl:choose>
      <xsl:when test="normalize-space($WholeDate) != ''">
        <xsl:value-of select="$MonthDisplayNum"/>/<xsl:value-of select="$Day" />/<xsl:value-of select="$Year" />&#160;<xsl:value-of select="$Hour" />:<xsl:value-of select="$Min" /><xsl:value-of select="$HourExt" />
      </xsl:when>
      <xsl:otherwise>

      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- XSL transformation starts here -->
  <xsl:template match="/">
    <div style="width:100%;text-align:left">
      Go to
      <a border="0">
        <xsl:attribute name="href">
          <xsl:value-of select="$listDefaultViewUrl"></xsl:value-of>
        </xsl:attribute>
        <img border="0">
          <xsl:attribute name="src">
            <xsl:value-of select="$listImageUrl"></xsl:value-of>
          </xsl:attribute>
        </img>
        &#160;
        <xsl:value-of select="$listTitle"></xsl:value-of>
      </a>
      <br/>
      <br/>
      <div style="font-size:12px;text-align:left;font-weight:bold">
        <span>Scheduled</span>
      </div>
      <xsl:call-template name="dvt_1.body">
        <xsl:with-param name="Status">Scheduled</xsl:with-param>
      </xsl:call-template>
      <br/>
      <br/>
      <div style="text-align:center;font-size:12px;">
        <a target="_blank">
          <xsl:attribute name="href">
            <xsl:value-of select="$siteUrl"></xsl:value-of>/Site%20Pages/Calendar_Scheduled.aspx
          </xsl:attribute>
          Go to Calender
        </a>
      </div>
      <br/>
      <br/>
      <div style="font-size:12px;text-align:left;font-weight:bold">
        <span>Implemented</span>
      </div>
      <xsl:call-template name="dvt_1.body">
        <xsl:with-param name="Status">Implemented</xsl:with-param>
      </xsl:call-template>
      <br/>
      <br/>
      <div style="text-align:center;font-size:12px;">
        <a target="_blank">
          <xsl:attribute name="href">
            <xsl:value-of select="$siteUrl"></xsl:value-of>/Site%20Pages/Implemented_RFCs_Dashboard_New.aspx
          </xsl:attribute>
          Go to List
        </a>
      </div>
      <br/>
      <br/>
    </div>
  </xsl:template>

  <!-- End of Stylesheet -->
</xsl:stylesheet>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions