Welcome to WebmasterWorld Guest from 54.167.157.247

Forum Moderators: httpwebwitch

Message Too Old, No Replies

XSL formatDateTime function

Transforming date and time

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



Hi

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"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2006/xpath-functions">

<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].')"/>
</xsl:template>

</xsl:stylesheet>

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?

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

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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:

[webmasterworld.com...]


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)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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.

Andy