Archive for February, 2022

XSLT : Converting decimal hours to hours minutes and seconds

February 16, 2022

If you want to convert decimal values into hours and minutes, and you are stuck with XSLT, use this.

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>

<xsl:variable name="decimal_hours" select="3.14"/>

<xsl:template match="/">
<xsl:value-of select="concat(
  format-number(floor($decimal_hours              ), '00:'),
  format-number(floor($decimal_hours *  60 mod  60), '00:'),
  format-number(floor($decimal_hours * 360 mod 360), '00'))"/>
</xsl:template>

</xsl:stylesheet>