Discussion:
date format using xslt 1.0
Jacob L
2012-06-12 17:47:34 UTC
Permalink
Hi,


I am trying to write an XSLT for formatting date.I am unable to find
any such previous posting,so sending it to the list.Here is my
requirement.

Input format:

<date>Mon, 11 Jun 2012 17:29:42 +0000 </date>

After the transform,I want output as:-

<date>20120611</date> which is YYYYMMDDkkmmss

Time at the end is not important.I am using XSLT 1.0 and SAX parser.

Thanks a lot!

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Andrew Welch
2012-06-12 19:51:54 UTC
Permalink
Post by Jacob L
Hi,
I am trying to write an XSLT for formatting date.I am unable to find
any such previous posting,so sending it to the list.Here is my
requirement.
<date>Mon, 11 Jun 2012 17:29:42 +0000 </date>
After the transform,I want output as:-
<date>20120611</date> which is YYYYMMDDkkmmss
Time at the end is not important.I am using XSLT 1.0 and SAX parser.
In xslt 1.0 I think you will just have to construct it using substring
along with a named template to map the months to numbers.
--
Andrew Welch
http://andrewjwelch.com

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Michael Kay
2012-06-12 20:08:32 UTC
Permalink
This might (or might not) be useful:

http://www.exslt.org/date/functions/parse-date/

Michael Kay
Saxonica
Post by Jacob L
Hi,
I am trying to write an XSLT for formatting date.I am unable to find
any such previous posting,so sending it to the list.Here is my
requirement.
<date>Mon, 11 Jun 2012 17:29:42 +0000</date>
After the transform,I want output as:-
<date>20120611</date> which is YYYYMMDDkkmmss
Time at the end is not important.I am using XSLT 1.0 and SAX parser.
Thanks a lot!
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
David Carlisle
2012-06-12 20:11:28 UTC
Permalink
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="date">
<xsl:variable name="a" select="substring-after(.,', ')"/>
<xsl:variable name="d" select="substring-before($a,' ')"/>
<xsl:variable name="b" select="substring-after($a,' ')"/>
<xsl:value-of select="concat(
substring-before(substring-after($b,' '),' '),
format-number(string-length(substring-before('xxxJanFebMarAprMayJunJulAugSepOctNovDec',substring-before($b,'
'))) div 3,'00'),
format-number($d,'00')
)"/>
</xsl:template>
</xsl:stylesheet>




--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Jacob L
2012-06-15 17:09:18 UTC
Permalink
Hi,

I am using this xslt shared by Mr.David.Can anyone help me with the
code to convert the time also.I previously sent message that it is not
important,but now the req. has changed.Thanks.

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="date">
<xsl:variable name="a" select="substring-after(.,', ')"/>
<xsl:variable name="d" select="substring-before($a,' ')"/>
<xsl:variable name="b" select="substring-after($a,' ')"/>
<xsl:value-of select="concat(
substring-before(substring-after($b,' '),' '),
format-number(string-length(substring-before('xxxJanFebMarAprMayJunJulAugSepOctNovDec',substring-before($b,'
'))) div 3,'00'),
format-number($d,'00')
)"/>
</xsl:template>
</xsl:stylesheet>
Post by Jacob L
Hi,
I am trying to write an XSLT for formatting date.I am unable to find
any such previous posting,so sending it to the list.Here is my
requirement.
<date>Mon, 11 Jun 2012 17:29:42 +0000 </date>
After the transform,I want output as:-
<date>20120611</date> which is YYYYMMDDkkmmss
Time at the end is not important.I am using XSLT 1.0 and SAX parser.
Thanks a lot!
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Liam R E Quin
2012-06-15 17:34:03 UTC
Permalink
Post by Jacob L
Hi,
I am using this xslt shared by Mr.David.Can anyone help me with the
code to convert the time also.I previously sent message that it is not
important,but now the req. has changed.Thanks.
I'd suggest taking the time to understand the solution you were sent
before, and trying to apply it to the time youself, before asking for
help. That way you will learn to walk, and if from time to time you
should stumble, there are people here who will catch you and help you up
again.

An approach using substring to pick out the time components will
probably work, maybe checking for the colon (:) to be more robust.

Note that the time is affected by the timezone, +0500 or whatever, and
decide whether you need to include that.

Liam
--
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/


--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Continue reading on narkive:
Loading...