Page 1 of 1

XSL and ISO8601 date/time

Posted: Tue Jun 21, 2016 12:24 am
by peter_b
This is a small collection of handling ISO8601 date/time/duration values with XML Stylesheets (XSLT).

Useful links:

HowTo: Quick-n-dirty ISO8601 duration from seconds

Posted: Tue Jun 21, 2016 12:30 am
by peter_b
This HowTo explains how to easily reformat a duration value in seconds (or nanoseconds, microseconds, etc) into an ISO8601 duration.

Assume, we have duration source value of 297,44 seconds.
Let's say we have it under the name "/Video/Duration".

Now, we just need to add the letter "P" (to indicate a duration), and "T" to indicate that it's time - and then "S" at the end, for seconds:

Code: Select all

<xsl:value-of select="concat('PT', /Video/Duration, 'S')"/>
It might not look as beautiful as formatted as hours, minutes, seconds - but it's actually easier to read back, parse and convert it to whatever output format you need.
:D