XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
David MartinSubject: Date formating
Author: David Martin
Date: 15 Nov 2005 12:58 PM
I'm new to date formating from within style sheets using xslt....but aging quickly.

How do I use and test ms:format-date from within Stylus 6?

It is not clear to me how Stylus supports testing the date-format spec exactly...and so I'm looking for a working set of date formating examples for testing within Stylus studio using MSXML 4 and preferrably MSXML 6. Since I'm using .NET ms:format-date seems to be what I want...however I would I'm not sure if that necessitates marking up my raw xml data.

<?xml version="1.0" standalone="yes"?>
<!-- [mytypicaldatesamplethatistrickytoformatinxslt.xml] -->
<dsMyData xml:space="preserve" xmlns:dt="urn:schemas-microsoft-com:datatypes">
<vw_my_data>
<my_date dt:dt="datetime">2005-11-15T10:01:00.0000000-04:00</my_date>
</vw_my_data>
</dsMyData>

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ms="urn:schemas-microsoft-com:xslt"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
<xsl:output method="html"/>
<xsl:template name="HowToFormatAdate">

<!-- I want to format this date MMM dd, yyyy hh:mm am ?-->
<xsl:value-of select="ms:format-date(dsMyData/vw_my_data/my_date, 'MMM dd, yyyy' )"/>

</xsl:template>
<xsl:template match="/">
<html><head></head>
<body/>
</html>
</xsl:template>
</xsl:stylesheet>

Output I want:
November 15, 2005 10:01 am


djm

Postnext
(Deleted User) Subject: Date formating
Author: (Deleted User)
Date: 15 Nov 2005 01:52 PM
David,

ms:format-date(dsMyData/vw_my_data/my_date, 'MMM dd, yyyy') and
ms:format-time(dsMyData/vw_my_data/my_date, 'hh:mm tt')

give you most of what you want. Are you also looking for something to do the timezone conversion to present the result in the local time zone?


Clyde Kessel


Unknowndate.xsl

Postnext
David MartinSubject: Date formating
Author: David Martin
Date: 15 Nov 2005 10:12 PM
ms:format-date does the trick and was all I wanted to use...just some "simple" date formating.

But I never managed to get it working for some reason using the studio (and still can't) - I may have mucked something up in my environment with various betas I was evaluating.


djm

Postnext
Ivan PedruzziSubject: Date formating
Author: Ivan Pedruzzi
Date: 15 Nov 2005 10:22 PM
Hi David,

Did you set the processor to be MSXML or .NET in the scenario dialog?
which error are you getting?

Thanks!
Ivan Pedruzzi
Stylus Studio Team

Postnext
(Deleted User) Subject: Date formating
Author: (Deleted User)
Date: 16 Nov 2005 09:17 AM
Dave,
Your original .xslt file had a couple of small errors.
Try the one I attached in my earlier post. Also, as Ivan suggested, make sure your processor is set to MSXML 4 (in the scenario processor tab).

- clyde

Postnext
GG KrishSubject: Date formating
Author: GG Krish
Date: 23 Nov 2005 12:06 PM
Originally Posted: 23 Nov 2005 12:05 PM
How about timezone info? Actually, we want to convert GMT time we are getting to local time. Thanks.

Postnext
(Deleted User) Subject: Date formating
Author: (Deleted User)
Date: 23 Nov 2005 12:53 PM
GG,

The original date presented as an example in this thread was:
2005-11-15T10:01:00.0000000-04:00
If you convert that using the ms:format-date function,
You get the equivalent UTC, namely 2:01 PM.
If you use substring() to strip off the "-4:00" at the end before
calling ms:format-date, you will get the local time, 10:01 AM.

- clyde

Postnext
GG KrishSubject: Date formating
Author: GG Krish
Date: 23 Nov 2005 12:57 PM
We DO NOT have the timezone portion in the timestamp info we get. It is simply a GMT timestamp. We need to add the timezone info based on the local time.

Postnext
(Deleted User) Subject: Date formating
Author: (Deleted User)
Date: 23 Nov 2005 01:11 PM
GG,

I don't know which timezone you are in, but suppose you are in EST like me. Then concatenate "+0400" to the end of the time stamp and do the conversion. I think you will get what you want.

clyde

Postnext
GG KrishSubject: Date formating
Author: GG Krish
Date: 23 Nov 2005 02:02 PM
We need to capture the timezone info based on the machine it is running on. It is NOT always EST.

Postnext
(Deleted User) Subject: Date formating
Author: (Deleted User)
Date: 23 Nov 2005 02:30 PM
So, if I understand correctly, you are getting a GMT time stamp from somewhere, and you want to convert it to the local time.

I need to understand your environment. Are you working with David (the person who started this thread?) If you are, then I assume you want to use the Microsoft date-time functions ms:....

If not, then what is your environment, what is your date format, and what functions are you using to manipulate them?

Thanks
Clyde

P.S. You are posting the same reply 2 or 3 times to the bulletin board.

Postnext
GG KrishSubject: Date formating
Author: GG Krish
Date: 23 Nov 2005 02:41 PM
We are in a .NET (but not .NET 2) environment.

Regarding multiple posts, looks like when I refresh the page, it "reposts" - so now I logoff after posting a reply to avoid this.

Thanks.

Postnext
(Deleted User) Subject: Date formating
Author: (Deleted User)
Date: 23 Nov 2005 04:38 PM
This is what I understand:

You get time stamps which look like this:
2005-11-15T10:01:00.0000000
without any time zone info. You are interpreting them as times in UTC, and want to convert them to the local time zone for display. You (or I) can write a Java extension function which gets the local time zone, and concatenate that (with a suitable + or -) and then use the ms:format-date and ms:format-time functions to do the time-zone offset.

One problem with this is that it will probably give the wrong answer right around the time that daylight savings goes on/off.

Does this solve your problem?
Clyde

Posttop
David MartinSubject: Date formating
Author: David Martin
Date: 25 Nov 2005 08:47 AM
Sorry for delay in responding and thanks for tips. ms:format-date and ms:format-time was exactly what I was trying to use all along. After my initial post and review of responses, I went back and tried calling the exact same routines again in my code, as is, and all worked fine (I had just mocked up a snippet for the post). It appears like I must have had some other issue at the time I was trying to initially implement the function call...and that sent me on quite a bit of a chase prior to posting actually.

Unfortunately, I changed several things along the way just prior to posting and so now to actually roll back to what my initial issue was...java jdk, eval studio (4->6), xslt processor (saxon 8.6x), restructured and linked xsl templates, .net (beta to release)...so I can not shed any light on what my original problem actually was (and we won't speculate on that one any further) but the likely issue was just a style sheet template usage mistake by me...eh hem, hem.

So I can now at least enjoy the satisfaction that xsl date formating works fine with the ms:format-date and ms:format-time calls as previous members have pointed out.

I did also hit the fact that ms:format-time applies the sql server gmt offset when formating the time. As previous posts point out the gmt can be appended (or modified)...if missing.

Thanks again,
djm

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.