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 June 3rd, 2014, 01:02 PM
Friend of Wrox
Join Date: Apr 2013
Posts: 101
Thanks: 14
Thanked 0 Times in 0 Posts
Default How do I format the date from xml document?

I have a xml document with the following node:

<ControlPoint Timestamp="3/25/2014 3:40:11 PM" UserID="XYZ">SAVE-THIS-EXAMPLE</ControlPoint>

I am using the following xslt selector to get the date for ExampleStatusDate.

<xsl:attribute name="ExampleStatusDate"><xsl:value-of select="//Start/ControlPoint/@Timestamp"/></xsl:attribute>

The result I am getting is 3/25/2014 3:40:11 PM

How can I format this xlst to just return ExampleStatusDate="3/25/2014"
Old June 3rd, 2014, 01:38 PM
mhkay's Avatar
Wrox Author
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

substring-before(//Start/ControlPoint/@Timestamp, ' ')
Note that to do dates and times properly (a) you need XSLT 2.0, and (b) you need to use international date-time formats rather than local US ones.
Michael Kay
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
winkimjr2 (June 3rd, 2014)

Similar Threads
Thread Thread Starter Forum Replies Last Post
date format differs, need to force format somehow patricolsson ASP.NET 2.0 Basics 1 December 3rd, 2009 12:53 AM
add 5 years to date in three nodes in xml document Boris1 XSLT 4 November 25th, 2009 11:18 AM
Problem with date format in XML and XML Schema nelly78 XML 3 October 23rd, 2009 09:43 AM
Convert British format date to American format? fyr PHP How-To 0 December 19th, 2007 03:17 PM
date format differs, need to force format somehow patricolsson HTML Code Clinic 2 January 12th, 2006 05:55 AM

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