Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 6th, 2004, 03:53 AM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default formatDate (date, format) problem

I'm trying to convert a date e.g. '02/03/1980' to '19800302' in an XSL transform.

I've found this function FormatDate()

 <xsl:value-of select="formatDate(APPLICANT/DATEOFBIRTH, 'YYYYMMDD')" />

but it just errors saying formatDate is not a valid XSLT or XPATH function.

Any ideas how I could perform this conversion would be most appreciated.

Francis

 
Old September 6th, 2004, 04:40 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

format-date() is a new function in XSLT 2.0. It takes as input a value of type xs:date (whose lexical form is always the ISO format YYYY-MM-DD). Your input date is not in ISO format so you can't use this function even with XSLT 2.0.

You can solve the problem by extracting the components of the string using substring() and recombining them using concat().



Michael Kay
http://saxon.sf.net/
 
Old September 6th, 2004, 05:08 AM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I was afraid you were going to say that.

I tried '02/03/1980':

<DATEOFBIRTH>
                <xsl:value-of select="concat(substring(APPLICANT/DATEOFBIRTH,7,10), substring(APPLICANT/DATEOFBIRTH,4,5), substring(APPLICANT/DATEOFBIRTH,1,2)) " />
            </DATEOFBIRTH>

and it created:

<DATEOFBIRTH>198003/1902</DATEOFBIRTH>

Most bizarre?


 
Old September 6th, 2004, 05:19 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Not bizarre if you read the spec. Check the meaning of the third arg to substring - it's a length, not a position.

Michael Kay
http://saxon.sf.net/
 
Old September 6th, 2004, 05:26 AM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Of course. Thanks for your help.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Date format problem abhishekkashyap27 C# 2005 1 June 23rd, 2008 02:25 AM
Date Format Problem cyberddindia Classic ASP Basics 2 October 23rd, 2006 01:49 AM
Date Format Problem Scripts82 Access VBA 2 March 13th, 2006 09:36 PM
Date format problem ERC Crystal Reports 1 June 15th, 2005 04:03 AM
Date format problem widad Classic ASP Basics 1 October 15th, 2004 06:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.