Applies to: SharePoint 2007
Anyone who has ever worked with SharePoint knows that creating filters on date values is not as straight forward as one would expect. This example explains how to compile employee birthdays in a custom list that automatically displays only the current month’s birthdays. With a few calculated columns, a data view, and minor XSLT this is easy to accomplish.
Figure 1 displays a screenshot my configured Birthdays list which displays only current month birthday entries on the home page of my site. To create your own list that filters by current month follow the below steps.
Getting Started – List Configuration (These steps are completed in the browser.)
1. Create a custom list and name it Birthdays.
2. Create the following columns:
Column 1) Birthday (birthday) / Date and Time / Field is Optional
Column 2) Birthday Month (birthdaymonth) / Calculated Column / Field is Hidden
Column 3) Day (day) / Calculated Column / Field is Hidden
Column 4) Employee (Title) / Single line of text / Field is Optional
Column 5) Month (month) / Calculated Column / Field is Hidden
Your column settings should display as in Figure 2 so that users do not see the hidden fields when a new birthday item is created.
3. Create a view in the Birthdays list and name it currentbirthdays. Columns to display are:
1- Birthday Month, 2- Day, and 3- Employee / Sort by: Day (ascending) and Month (ascending).
Birthday list content and configuration
Before proceeding to the Final Stretch section ensure your list contains the following:
Final Stretch – XSLT filtering in SharePoint Designer 2007
An XSLT filter is used to display only current month birthdays. The XSLT expression uses the hidden Month column to compare the Birthday Month column to [Today’s] month.
NOTE: In SharePoint 2010 create the Birthdays list then, in Designer, add an empty data source to a page. Connect to the Birthdays list and add the columns (Birthday Month, Day, and Employee). Access the filter settings and follow the below instructions.
4. Open SharePoint Designer. Navigate to the Birthdays list and double-click the currentbirthdays.aspx page to open it.
5. Right-click and convert the list to an XSLT Data View.
6. Right-click the data view web part and choose Show Common Control Tasks.
7. Choose Filter.
8. Check the Add the XSLT Filtering option and choose Edit. The Advanced Condition dialogue box opens.
9. In the Edit the XPath Expression field input the following XSLT and then click OK:
10. Select Ok to close the Advanced Condition dialogue box.
11. Close Designer. If prompted to Save or Check-in, do so.
NOTE: After adding the list as a web part to a page or site, it may be necessary to repeat steps 4 – 11.