none
Date functions in XSLT

    General discussion

  • Hi!

    For my Custom Query Web Part in Sharepoint I am customizing the XSLT file which selects every item from the lists which datefield(MM/dd) = today(MM/dd). This works, but now I also want to show the items from yesterday and the items which datefield is 3 days from today. (It's about a birthdaylist). I tried the date:add P1D function to fill a variabele with tomorrow's date but it's not working at all!  No error messages so I am kinda stuck here.

    Below you can find my XSLT code. What am I doing wrong? Or is there a other/better way to solve this?

    Regards,
    Erik

    1 <xsl:stylesheet   
    2 version="1.0"   
    3 exclude-result-prefixes="x d xsl msxsl cmswrt ddwrt date" 
    4 xmlns:x="http://www.w3.org/2001/XMLSchema"   
    5 xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"   
    6 xmlns:cmswrt="http://schemas.microsoft.com/WebParts/v3/Publishing/runtime" 
    7 xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
    8 xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date" 
    9 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">  
    10  
    11 <xsl:template name="Birthday" match="Row[@Style='Birthday']" mode="itemstyle">  
    12 <xsl:variable name="SafeLinkUrl">  
    13 <xsl:call-template name="OuterTemplate.GetSafeLink">  
    14 <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>  
    15 </xsl:call-template> 
    16 </xsl:variable> 
    17 <xsl:variable name="DisplayTitle">  
    18 <xsl:call-template name="OuterTemplate.GetTitle">  
    19 <xsl:with-param name="Title" select="@Title"/>  
    20 <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>  
    21 </xsl:call-template> 
    22 </xsl:variable>           
    23  
    24 <xsl:variable name="currentDatePlus1">  
    25 <xsl:call-template name="date:add">  
    26 <xsl:with-param name="date-time" select="date:date"/>  
    27 <xsl:with-param name="duration" select="'P1D'"/>  
    28 </xsl:call-template> 
    29 </xsl:variable> 
    30    
    31 <xsl:variable name="LinkTarget">  
    32 <xsl:if test="@OpenInNewWindow = 'True'" >_blank</xsl:if> 
    33 </xsl:variable> 
    34 <div id="linkitem" class="item link-item">  
    35  <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>  
    36 <xsl:value-of select="currentDatePlus1" /> 
    37 </div> 
    38              
    39 </xsl:template> 
    40 </xsl:stylesheet> 
    Wednesday, February 11, 2009 1:27 PM

All replies

  • I don't know about XSLT in Sharepoint but for .NET the following holds:

    XSLT 1.0 as implemented by XslCompiledTransform in the .NET framework does not have any date or dateTime data type support or any functions for working with date or dateTime values.
    You would need to use XSLT 2.0 to do that but Microsoft so far does not have any implementation of that so you would need to use a third party solution like Saxon 9 or AltovaXML tools where I don't know whether you could integrate them in Sharepoint.

    EXSLT also has some date support I think but XslCompiledTransform does not support EXSLT either so you would need to make use of the library http://www.codeplex.com/MVPXML, again I don't know whether you could integrate that in Sharepoint.

    MVP XML
    Wednesday, February 11, 2009 1:46 PM
  • Hi

    I am on a SharePoint project and my client wants to rollup content and sort / filter / group based on certain dates held in a custom task list.

    I tried some EXSLT and also http://www.xqueryfunctions.com/   all I was able to achieve was to see how many different types of XML exception I could get to appear in the  SharePoint ULS logs!!!!!!!! Rule of thumb: if Devs aren't showing off how to use these functions in their blogs it ain't happening!

    It kind of makes me stuck as I am poised to go down the custom web Part route .

    I want to be create the day number or Day name from a given date. then I want to determine the start of the week from a given date. Thereafter build  a 

    table that references the (start of each week + 6) against tasks whose due date falls within that week or a task whose start date falls within that week

    Daniel

    Wednesday, April 04, 2012 4:11 PM
  • For Sharepoint related questions you might want to try http://social.msdn.microsoft.com/Forums/en-US/category/sharepoint2010,sharepoint/.

    Here we can help you write XSLT 1.0 for Microsoft's XslCompiledTransform or XSLT 2.0 for third party XSLT 2.0 processors on Windows (i.e. AltovaXML, Saxon .NET, XmlPrime) but integrating such stuff in Sharepoint is a different matter.

    For Microsoft's XslCompiledTransform, to access or use functionality in the .NET framework class library (as for instance the System.DateTime and calendar functionality) see http://msdn.microsoft.com/en-us/library/6datxzsd.aspx.


    MVP Data Platform Development My blog

    Wednesday, April 04, 2012 4:34 PM
  • Martin

    Thanks I hadn't realised I had stumbled into this forum. I am curious though to see  how in XSLT 1.0 you can obtain the start of the a week (date) when given date as a parameter - Is this easier to do?

    Daniel

    Wednesday, April 04, 2012 4:59 PM
  • Well XSLT 1.0 has no date data type and no support for working with dates. The .NET framework however has (see http://joelabrahamsson.com/entry/getting-the-first-date-in-a-week-with-c-sharp for instance) and with the links posted earlier you can use .NET framework code from XSLT executed with XslCompiledTransform (by using the extension object mechanism or by using the ms:script extension element to use extension functions written in .NET).

    MVP Data Platform Development My blog

    Wednesday, April 04, 2012 5:13 PM