homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

XSL formatDateTime function
Transforming date and time

 4:29 pm on Mar 9, 2011 (gmt 0)


I'm totally new to XSL and I'm trying to get the format-dateTime() function to work...

From the web I found this simple bit of code:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"

<xsl:output method="text"/>

<xsl:template match="/">

<xsl:text>&#xA; It's currently </xsl:text>
<xsl:value-of select="current-dateTime()"/>
<xsl:value-of select="format-dateTime(current-dateTime(),'[h01]:[m01] [P] on [FNn] the [D1o].')"/>


which should, given any XML, print out the date and time. But if I run it in XMLSpy I get "Unknown XPath function"

When I run this in [w3schools.com...]

it seems to just ignore the 2 date functions and just prints out "It's currently"

I'm sure I'm doing something stupid - can anyone assist?




 6:49 pm on Mar 9, 2011 (gmt 0)

format-dateTime is part of the XSLT2.0 specification. So is current-dateTime().

Not all parsers are up to 2.0 - for example PHP is still built with only support for XSLT1.0

quoting myself, from 4 years ago:


There is only one known XSLT2 processor called SAXON (http://saxon.sourceforge.net/), built by Michael Kay, which was released for the Java and .NET platforms.

Other XSLT processors, including Sablotron, Xalan and MSXML, have not yet adopted XSLT2.

Things haven't changed much since then.

What does your input XML look like? It'll be much easier to format the date in the input so it looks like you want it to, rather than try to create and format it using an XPath transformation.


 6:51 pm on Mar 9, 2011 (gmt 0)

Are you doing this transformation client-side, or server-side?

... because you can't rely on client-side XSLT (in the browser) to be using a 2.0 parser either.

Welcome to WebmasterWorld!


 11:21 am on Mar 11, 2011 (gmt 0)

Thanks for the info!

I'm doing the transform in a Java program, but I've found my company does not use 2.0 - so I've had to format the dates manually.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved