1

I have RSS viewer webpart inserted in SharePoint page. I have to show only today's feed, so have to compare todays date in XSL file which is already provided by the webpart. Below is the code of the same.

<xsl:template name="RSSMainTemplate.description">
        <xsl:param name="DescriptionStyle"/>
        <xsl:param name="CurrentElement"/><div id="{$CurrentElement}" class="description" align="{$rss_alignValue}" style="{$DescriptionStyle} text-align:{$rss_alignValue};">
            <xsl:choose>
                <!-- some RSS2.0 contain pubDate tag, some others dc:date -->
                <xsl:when test="string-length(pubDate) &gt; 0">
                    <xsl:variable name="pubDateLength" select="string-length(pubDate) - 3" />
            <xsl:value-of select="ddwrt:FormatDate(substring(pubDate,0,$pubDateLength),number($rss_LCID),3)"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="ddwrt:FormatDate(string(dc:date),number($rss_LCID),3)"/>
                </xsl:otherwise>
            </xsl:choose>

so how to compare it with today's date (only day i.e 13th feb).

user3266990
  • 111
  • 2

1 Answers1

0

Comparing Dates in SharePoint Using XSL

The following functions are commonly used to return the current DateTime:

  • ddwrt:Today()
  • ddwrt:TodayISO()

In case of RSS Viewer web part, the following code demonstrates how to compare if RSS item was published today:

<xsl:variable name="todayDateFmt" select="ddwrt:FormatDate(ddwrt:TodayIso(),number($rss_LCID),3)" />
<xsl:variable name="pubDateFmt" select="ddwrt:FormatDate(pubDate,number($rss_LCID),3)" />
<xsl:if test="msxsl:string-compare($pubDateFmt,$todayDateFmt) = 0">
    <!-- -->              
</xsl:if>

Example

The following XSL template demonstrates how to apply item formatting in RSS Viewer web part (the items published today are highlighted with color):

<xsl:template name="RSSMainTemplate.body" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
    <xsl:param name="Rows"/>
    <xsl:param name="RowCount"/>
    <xsl:for-each select="$Rows">
      <xsl:variable name="CurPosition" select="position()" />
      <xsl:variable name="RssFeedLink" select="$rss_WebPartID" />
      <xsl:variable name="CurrentElement" select="concat($RssFeedLink,$CurPosition)" />
      <xsl:if test="($CurPosition &lt;= $rss_FeedLimit)">

        <xsl:variable name="todayDateFmt" select="ddwrt:FormatDate(ddwrt:TodayIso(),number($rss_LCID),3)" />
        <xsl:variable name="pubDateFmt" select="ddwrt:FormatDate(pubDate,number($rss_LCID),3)" />
        <xsl:choose>
          <xsl:when test="msxsl:string-compare($pubDateFmt,$todayDateFmt) = 0">
            <xsl:call-template name="RSSMainTemplate.item">
              <xsl:with-param name="ItemStyle" select="string('display:block;background-color:#A5FF7F;')"/>
              <xsl:with-param name="CurrentElement" select="$CurrentElement"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="RSSMainTemplate.item">
              <xsl:with-param name="ItemStyle" select="string('display:block;')"/>
              <xsl:with-param name="CurrentElement" select="$CurrentElement"/>
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>

Complete xsl file for Rss Viewer web part

enter image description here

Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193