I want to convert a time-format like "HH:MM:SS.SSS" into Milliseconds using tokenize and/or analyze-string() with XSLT 1.0.
The following xsl-Stylesheet:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:pc="https://purl.org/net/hbuschme/teaching/2019ws-infostruk/podcast/0.3"
xmlns:pt="https://purl.org/net/hbuschme/teaching/2019ws-infostruk/podcast-transcript/0.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
exclude-result-prefixes="exsl">
<xsl:output method="xhtml"/>
<xsl:template match="pc:podcast">
<html>
<body>
<h1>Episoden des Podcasts <i><xsl:value-of select="pc:title"/></i></h1>
<xsl:apply-templates select="pc:episode"/>
</body>
</html>
</xsl:template>
<xsl:template match="pc:episode">
<p>
Episode <xsl:value-of select="@episode"/> <xsl:text> </xsl:text> <xsl:number format="1. "/>
<xsl:text></xsl:text>
<b><xsl:value-of select="@title"/></b> <br/>
<xsl:value-of select="pt:transcript"/>
<xsl:for-each select="pc:chapter"><ul>
<xsl:number count="pc:episode|pc:chapter" level="multiple" format="1.1. "/>
<xsl:value-of select="@title" />
</ul></xsl:for-each>
<xsl:for-each select="@url">
<xsl:sort select="@episode" order="descending" /><a href="{@url}"><xsl:apply-templates/></a>
</xsl:for-each>
<xsl:call-template name="time-to-milliseconds">
<xsl:with-param name="time" select="@duration"/>
</xsl:call-template>
<xsl:call-template name="mt">
<xsl:with-param name="time" select="@duration"/>
</xsl:call-template>
</p>
</xsl:template>
<xsl:template name="time-to-milliseconds">
<xsl:param name="time"/>
<xsl:param name="h" select="substring-before($time, ':')"/>
<xsl:param name="m" select="substring-before(substring-after($time,':'),':')"/>
<xsl:param name="s" select="substring-after(substring-after($time,':'),':')"/>
<xsl:choose>
<xsl:when test="contains($h, '00')">
<xsl:value-of select="1000*(60*$m + $s)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="1000*(3600*$h + 60*$m + $s)"/>
</xsl:otherwise>
<xsl:when test="contains($m, '00')">
<xsl:value-of select="1000*(3600*$h + $s)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="1000*(3600*$h + 60*$m + $s)"/>
</xsl:otherwise>
<xsl:when test="contains($s, '00')">
<xsl:value-of select="1000*(3600*$h + 60*$m)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="1000*(3600*$h + 60*$m + $s)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="mt">
<xsl:param name="time"/>
<xsl:param name="h" select="floor($time div 3600000)"/>
<xsl:param name="m" select="floor($time mod 3600000 div 60000)"/>
<xsl:param name="s" select="floor($time mod 60000 div 1000)"/>
<xsl:value-of select="concat($h,':',$m,':',$s,':')"/>
</xsl:template>
</xsl:stylesheet>
Expected output:
00:42 -> 4200
Any advice? I do not know how or if I can even use the analyze-string function in XSLT 1.0. Can you provide me with an example of how to handle this problem?