Solved

XSLT format-date() not recognised as a function.  What am I doing wrong

Posted on 2011-09-10
3
332 Views
Last Modified: 2012-05-12
I have an xml file with a date e.g
<expenseDate>2011-07-31T00:00:00</expenseDate> and I want to format it So iy reads
July 32, 2011.  When creating the stylesheet I tried the following
 <td>
      <xsl:value-of select="format-date(expenseDate, '[MNn] [D1], [Y]'])" />
 </td>
However I get an error when displaying the web page saying that format-date() is not a recognised function in XSLT (I am using version="2".  

Any help appreciated
0
Comment
Question by:ddefreitas
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
Comment Utility
format-date() is a function that is only available in XSLT2.
It is not sufficient to label the version="2.0"
The processor you use should be able to process XSLT2 stylesheets

Since you tag this question with Visual Studio 2010, you are likely using MSXML and there is no version 2.0 support in MSXML
You could potentially use the .NET version of saxon (see www.saxonica.com)

The reason you don't get an error on teh version="2.0" is that XSLT processors are forward-wards compatible
So an XSLT1 stylesheet can run an XSLT2 stylesheet, but will report all unknown functionality unless there is a fallback
That is why you don't get a report about the stylesheet version, but only at the level of the function

There is no alternative for format-date in XSLT1.
But you can check for extensions that work for msxml in www.exslt.org
0
 

Author Closing Comment

by:ddefreitas
Comment Utility
Thanks, very comprehensive explanation.  
Will try these but have managed to get the correct format from the database so will close this question
Kind regards
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
welcome,
if data comes from a database it is always more advisable to do the formatting there.
XSLT1 is not fit for doing complex string manipulation, and there is no date format.
even in XSLT2 I find the date data model is a bit broken (or at least limited)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now