[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Convert ISO8601 Date with XSLT

Subject: RE: Convert ISO8601 Date with XSLT
From: "David B. Bitton" <david@xxxxxxxxxxxxxx>
Date: Wed, 06 Feb 2002 19:36:37 -0500
xslt convert date
This is what I use:

	<!--
		formatdate
	-->
	<xsl:template name="formatdate">
		<xsl:param name="node"/>
		<xsl:param name="html">1</xsl:param>
		<xsl:variable name="date"
select="concat(substring(string($node),6,2),'/',substring(string($node),
9,2),'/',substring(string($node),1,4))"/>
		<xsl:variable name="time"
select="substring(string($node),12,5)"/>
		<xsl:choose>
			<xsl:when test="$node[@type='Date']">
				<xsl:value-of select="$date"/>
			</xsl:when>
			<xsl:when test="$node[@type='DateTime']">
				<xsl:choose>
					<xsl:when test="$html = 1">
						<xsl:value-of
select="concat($date,'&lt;br&gt;',$time)"
disable-output-escaping="yes"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of
select="concat($date,' ',$time)"/>
					</xsl:otherwise>
				</xsl:choose>				
			</xsl:when>
		</xsl:choose>
	</xsl:template>

And then I use it like this:

<xsl:call-template name="formatdate">
	<xsl:with-param name="node" select="Element"/>
</xsl:call-template>

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Snow, Corey
> Sent: Wednesday, February 06, 2002 6:08 PM
> To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
> Subject:  Convert ISO8601 Date with XSLT
> 
> 
> Hi all,
> 
> I have an XML document that looks like the following (sanitized):
> 
> <log>
> 	<logentry class="Information">
> 		<logtime>2002-02-06T14:46:52</logtime>
> 		<event>Log Cleared</event>
> 	</logentry>
> </log>
> 
> I also have an XML schema that defines the content of the 
> "logtime" element to be a dateTime value. This document 
> validates properly against my schema, and I can display the 
> document properly using my XSLT stylsheet, which basically 
> just formats the document as a table- the real thing has many 
> log entries, obviously.
> 
> Here's the problem: I may have a need to work with this date 
> value in various other locations, using tools such as 
> VBScript. Unfortunately, the string value above isn't 
> recognized as a valid date by the various date-handling 
> functions in VBScript, such as IsDate() or FormatDateTime(). 
> The irony is that in order to generate an ISO8601-compliant 
> datetime value when writing the file, I had to write a custom 
> function to convert the datetime representation created by 
> VBScript into ISO8601 format. I suppose I could have simply 
> made the content of the "logtime" element a string and be 
> done with it, but that didn't seem very clean to me.
> 
> What I need to know is the "best" method to convert this date 
> into another format using XSLT. I could, of course, simply 
> use the substring-before() and
> substring-after() functions to modify the display of 
> information, which is what I am currently assuming is the way 
> to go. There's other ways also- by using VBScript it would be 
> trivial to take the string apart. I'm mostly looking to see 
> if this problem is one that others have had and what the most 
> portable way of solving it is.
> 
> Regards,
> 
> Corey Snow
> 
> #########################################################
> The information contained in this e-mail and subsequent 
> attachments may be privileged, 
> confidential and protected from disclosure.  This 
> transmission is intended for the sole 
> use of the individual and entity to whom it is addressed.  If 
> you are not the intended 
> recipient, any dissemination, distribution or copying is 
> strictly prohibited.  If you 
> think that you have received this message in error, please 
> e-mail the sender at the above 
> e-mail address. 
> #########################################################
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.