在Rss查看器XSL中比较日期

时间:2014-02-13 12:44:15

标签: xslt sharepoint rss

我在SharePoint页面中插入了RSS查看器webpart。 我必须只显示今天的feed,所以必须比较已经由webpart提供的XSL文件中的今天日期。 以下是相同的代码。

<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>

所以如何将它与今天的日期(仅一天,即13日)进行比较。

1 个答案:

答案 0 :(得分:0)

使用XSL比较SharePoint中的日期

以下函数通常用于返回当前DateTime

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

对于RSS Viewer Web部件,以下代码演示了如何比较今天是否发布RSS项目:

<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>

实施例

以下XSL模板演示了如何在RSS Viewer Web部件中应用项目格式(今天发布的项目用颜色突出显示):

<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

相关问题