XSL Day of Week Function

Topics: General, XSLT
Aug 2, 2011 at 8:30 PM

I am trying to create a function that will provide me with Today's day of the week (ie: Monday).  I am going to use this to display information for that day only.  I found this article, but got lost trying to use it in C1's XSLT Functions.  

The article I found (not sure if this is what I need to do or is the best way to do it): http://www.xsltfunctions.com/xsl/functx_day-of-week-name-en.html

Any help would be great.

Thanks,

Rob

Aug 2, 2011 at 8:41 PM
Edited Aug 2, 2011 at 8:43 PM

You should always use the best tool for the job, and here it would be to let the .Net framework tell you this information. Write an XSLT extension that simply returns DateTime.DayOfWeek or DateTime.ToString("dddd")

http://docs.composite.net/C1/XSLT/Adding-an-XSLT-extension.aspx
http://msdn.microsoft.com/en-us/library/system.datetime.dayofweek.aspx 

Aug 2, 2011 at 9:18 PM
Edited Aug 2, 2011 at 9:18 PM

There is already an XSLT extension that can do this - see http://docs.composite.net/C1/XSLT/GuideToXsltFunctions.aspx/Editing-the-Template#_Toc273359170

First include the C1 Function that introduce this XSLT extension (see the guide) and the use something like ns:Format("20110702T22:17", "ddd") - this should return "Tuesday".

Aug 4, 2011 at 3:41 AM

 

Hi Mawtex,
I tried using your suggestion.  I need to get that today is "Wednesday".  I was able to follow the guide in the C1 Docs to get the Month (number), Day (Number), Year (number).  I can not seem to get the day of week.  Any suggestions of what I am doing wrong?

My Code:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:in="http://www.composite.net/ns/transformation/input/1.0" xmlns:lang="http://www.composite.net/ns/localization/1.0" xmlns:f="http://www.composite.net/ns/function/1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:df="#dateExtensions" exclude-result-prefixes="xsl in lang f df">
  <xsl:template match="/">
    <html>
      <head></head>
      <body>
        
          <xsl:value-of select="df:Format(/in:inputs/in:result[@name='DateTime'],ddd)" />
        
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

OUTPUT

<html xmlns="http://www.w3.org/1999/xhtml">
    <head/>
    <body>8/3/2011 12:00:00 AM</body>
</html>

 

 

Aug 4, 2011 at 7:09 AM

Hello,

The format string should be within quotes : 'dddd'

 

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:in="http://www.composite.net/ns/transformation/input/1.0" xmlns:lang="http://www.composite.net/ns/localization/1.0" xmlns:f="http://www.composite.net/ns/function/1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:df="#dateExtensions" exclude-result-prefixes="xsl in lang f df">
  <xsl:template match="/">
    <html>
      <head></head>
      <body>
        
          <xsl:value-of select="df:Format(/in:inputs/in:result[@name='DateTime'],'dddd')" />
        
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

Aug 5, 2011 at 5:48 AM

Worked great!  Thank you.