Monday, July 7, 2008

Adding the New icon for content based on modified date.

Add to xsl:stylesheet tag:


xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"


Then add this template to be called later:


<xsl:template name="OuterTemplate.IsNew">
       <xsl:param name="ModifiedValue"/>
        <xsl:if test="((ddwrt:FormatDateTime(string(ddwrt:Today()), 1033, 'yyyyMMdd')) - (ddwrt:FormatDateTime(string($ModifiedValue), 1033, 'yyyyMMdd'))) &lt; 5" >
         <xsl:value-of select="string('&lt;img src=&quot;/_layouts/1033/images/new.gif&quot; alt=&quot;New&quot; /&gt;')"/>
  </xsl:if >
    </xsl:template>


Example of using the template:


<xsl:variable name="NewIcon">
         <xsl:call-template name="OuterTemplate.IsNew">
       <xsl:with-param name="ModifiedValue" select="@Modified"/>
    </xsl:call-template>
  </xsl:variable>


<xsl:value-of  disable-output-escaping="yes" select="$NewIcon"/>

No comments: