Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT Format Date

I have a date in this format

10/12/2011 12:55:00 PM (MM-DD-YYYY time)

I would like to format this date into

12/10/2011 (DD-MM-YYYY) time to be removed 

using XSLT? the complexity I find is sometimes the input date can look like

7/12/2011 12:55:00 PM (only one number to the front instead of 07)

Can someone please show me a way to implement this? many thanks in advance.

like image 692
Chin Avatar asked Oct 08 '22 20:10

Chin


1 Answers

It is easy to obtain desired result using only standard XPath string functions like substring-before, substring-after and substring, e.g.:

<xsl:variable name="input">7/12/2011 12:55:00 PM</xsl:variable>

<xsl:value-of select="concat(
              substring-before(substring-after($input, '/'), '/'), '/',
              substring-before($input, '/'), '/',
              substring(substring-after(substring-after($input, '/'), '/'), 1, 4)
              )"/>
like image 196
Kirill Polishchuk Avatar answered Oct 12 '22 02:10

Kirill Polishchuk