Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 340
  • Last Modified:

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

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
ddefreitas
Asked:
ddefreitas
  • 2
1 Solution
 
Geert BormansCommented:
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
 
ddefreitasAuthor Commented:
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
 
Geert BormansCommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now