This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Convert ISO8601 Date with XSLT
- From: "David B. Bitton" <david at codenoevil dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 06 Feb 2002 19:36:37 -0500
- Subject: RE: [xsl] Convert ISO8601 Date with XSLT
- Organization: Code No Evil, LLC
- Reply-to: xsl-list at lists dot mulberrytech dot com
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,'<br>',$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@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of
> Snow, Corey
> Sent: Wednesday, February 06, 2002 6:08 PM
> To: 'xsl-list@lists.mulberrytech.com'
> Subject: [xsl] 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