format-DateTime with XSL

Posted by: Clarity Blogs: ASP.NET, on 16 Oct 2009 | View original | Bookmarked: 0 time(s)

I had to take a DateTime in the format of 2009-10-23 00:00:00 and convert it to 10/23/2009 using XSL.  XSL 1.0 doesnt have any type of datetime formatting functions, so the following snippet should help anyone else in a similar predicament:

 

<xsl:element name="newdate">
         <xsl:call-template name="FormatDate">
           <xsl:with-param name="DateTime" select="@Date"/>
         </xsl:call-template>
       </xsl:element>

<xsl:template name="FormatDate">
   <xsl:param name="DateTime" />
   <xsl:variable name="Year">
     <xsl:value-of select='substring-before($DateTime,"-")'/>
   </xsl:variable>
   <xsl:variable name="NoYear">
     <xsl:value-of select='substring-after($DateTime,"-")'/>
   </xsl:variable>
   <xsl:variable name="Month">
     <xsl:value-of select='substring-before($NoYear,"-")'/>
   </xsl:variable>
   <xsl:variable name="DayWithTime">
     <xsl:value-of select='substring-after($NoYear,"-")'/>
   </xsl:variable>
   <xsl:variable name="Day">
     <xsl:value-of select='substring-before($DayWithTime," ")'/>
   </xsl:variable>
   <xsl:value-of select='$Month'/>
   <xsl:text>/</xsl:text>
   <xsl:value-of select='$Day'/>
   <xsl:text>/</xsl:text>
   <xsl:value-of select='$Year'/>
</xsl:template>

Advertisement
Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.
Category: XML | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 2311 | Hits: 13

Similar Posts

  • SQL SERVER Denali Date and Time Functions DATEFROMPARTS() DATETIMEFROMPARTS() DATETIME2FROMPARTS() TIMEFROMPARTS() SMALLDATETIMEFROMPARTS() DATETIMEOFFSETFROMPARTS() A Quick Introduction more
  • Eschewing Date Types in our Database more
  • Accessing Images On Flickr From An ASP.NET Website Using The Flickr.Net Library more
  • LINQ Tip of the week: System.DateTime support more
  • Single Project Areas With ASP.NET MVC 2 Preview 1 more
  • Export Word documents to XPS - Open XML Paper Specification format more
  • The Fibonacci Blog Post Formatter more
  • Eloquera Database - the web-oriented client/server object database for .NET more
  • Visual Studio Talk Show #100 is now online (French) more
  • Export Word to PDF docs compliant to PDF/A-1b via Aspose.Words more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD