Solved

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

Posted on 2011-09-10
3
338 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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