XSLT 2.0 – Even More on Dates

Recently, I needed to get the minimum and maximum dates from a SharePoint Task list. With XSLT 1.0, you typically accomplish this by iterating over your rows and sorting them in the order you want, then grabbing the first or last value to get the min or max date you want.  This can get cumbersome when you need to do this on more than a couple of fields.

So I took advantage of the opportunity to see what XSLT 2.0 had to offer.  Sure enough there is a min() and max() function and they work just like you would expect them to.

Using a Task list as an example, we can quickly find minimum start and maximum due dates for the entire set of tasks with two lines of XSL applied to our raw CAPS output.


<xsl:value-of select=” min(NewDataSet/Tasks/cw:listitems/rs:data/z:row/@ows_StartDate/xs:dateTime(.))”/>



<xsl:value-of select=” max(NewDataSet/Tasks/cw:listitems/rs:data/z:row/@ows_DueDate/xs:dateTime(.))”/>


We have to append our selected node with “/xs:dateTime(.)” so that the XSLT 2.0 engine will compare values as dates and not strings.

You will also want to make sure that you are including “<DateInUtc>TRUE</DateInUtc>” in the CAML of your CAPS call as well.

If you need to refresh your memory about working with dates in xslt 2.0 and CAPS here are our two prior blogs covering formatting and doing calculations.

Comments are closed.