Solved

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

Posted on 2011-09-10
3
333 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
ID: 36515934
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
ID: 36516014
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
ID: 36516168
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

23 Experts available now in Live!

Get 1:1 Help Now