So, I’ve been screwing around with the data view webpart a bit more and figured this bit of code I came up with would come in handy for others. What it does is compare two fields and if they match doesn’t show one of the fields. If they do match it shows the full date span of the two fields.
<xsl:if
test="not(ddwrt:FormatDateTime(string(@EndDate) ,1033 ,’MMMM dd’) =
ddwrt:FormatDateTime(string(@EventDate) ,1033 ,’MMMM dd’))”>
<span> //data to show if the values don’t match
- <xsl:value-of select="ddwrt:FormatDateTime(string(@EndDate) ,1033 ,’MMMM dd’)” />
</span>
</xsl:if>
In this case I took a Calendar Data View and comparing the Start Time (@EventDate) with the End Time (@EndDate), I modified the formatting of each to be friendly month name (July instead of 07) and if they match it ignores showing the end date. This comparison code can be useful for other things too. You could also be really cool with it and make it so it shows differential data. So like Product1 = $50 and Product2 = $70 and have it show the difference in cost/profit etc.
Should be handy.
Comments: (2)
AlphaAlien on Mon, Jul 13th, 2009 at 02:41 AM
An extended version of this filter that shows hour span for 1 day items along with date of occurrence, and date span for multi-day events.
<xsl:if test="not(ddwrt:FormatDateTime(string(@EventDate), 1033, ‘MMMM dd’) = ddwrt:FormatDateTime(string(@EndDate), 1033, ‘MMMM dd’))">
<span>
- <xsl:value-of select="ddwrt:FormatDateTime(string(@EndDate), 1033, ‘MMMM dd’)">
</span>
</xsl:if>
<xsl:if test="not(ddwrt:FormatDateTime(string(@EventDate), 1033, ‘MMMM dd’) != ddwrt:FormatDateTime(string(@EndDate), 1033, ‘MMMM dd’))">
<span>
- <xsl:value-of select="ddwrt:FormatDateTime(string(@EndDate), 1033, ‘h:mm tt’)">
</span>
</xsl:if>
AlphaAlien on Wed, Jul 29th, 2009 at 03:58 PM
Alright, think this is the final revision of the above code. It does proper hour and date spans.
ie and event going from august 3rd -> 7th will now show: Aug 03 - Aug 07 instead of Aug 03 12:00am -> Aug 07
<!-- Starting date/time -->
<xsl:if test="ddwrt:FormatDateTime(string(@EventDate), 1033, ‘MMMM dd’)
!= ddwrt:FormatDateTime(string(@EndDate), 1033, ‘MMMM dd’)">
<span>
<xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate), 1033, ‘MMM dd’)” >
</span>
</xsl:if>
<xsl:if test="ddwrt:FormatDateTime(string(@EventDate), 1033, ‘MMMM dd’)
= ddwrt:FormatDateTime(string(@EndDate), 1033, ‘MMMM dd’)">
<span>
<xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate), 1033, ‘MMM dd h:mm tt’)” >
</span>
</xsl:if>
<!-- End date/time -->
<xsl:if test="ddwrt:FormatDateTime(string(@EventDate), 1033, ‘MMMM dd’)
!= ddwrt:FormatDateTime(string(@EndDate), 1033, ‘MMMM dd’)">
<span>
- <xsl:value-of select="ddwrt:FormatDateTime(string(@EndDate), 1033, ‘MMM dd’)” >
</span>
</xsl:if>
<xsl:if test="ddwrt:FormatDateTime(string(@EventDate), 1033, ‘MMMM dd’)
= ddwrt:FormatDateTime(string(@EndDate), 1033, ‘MMMM dd’)">
<span>
- <xsl:value-of select="ddwrt:FormatDateTime(string(@EndDate), 1033, ‘h:mm tt’)” >
</span>
</xsl:if>
Page 1 of 1 pages


















Post Tags: sharepoint dataview xslt
Next entry: First Look at SharePoint 2010 Previous entry: Windows Update is Intelligent