-1

I hope the question is clear. I want the sum of the "speech share" from guest and host seperatly and for each episode.

Here is an example of my xml file:

<?xml version="1.0" encoding="UTF-8"?>
<pc:podcast url="https://forschergeist.de/" version="0.3" 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:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="   https://purl.org/net/hbuschme/teaching/2019ws-infostruk/podcast/0.3   podcast.xsd   https://purl.org/net/hbuschme/teaching/2019ws-infostruk/podcast-transcript/0.1   podcast-transcript.xsd">
    <pc:title>Forschergeist</pc:title>
    <pc:persons>
        <pc:person gender="male" pid="timpritlove">Tim Pritlove</pc:person>
        <pc:person gender="male" pid="michaelsonnabend">Michael Sonnabend</pc:person>
        <pc:person gender="female" pid="annettevogt">Annette Vogt</pc:person>
        <pc:person gender="male" pid="peterfinke">Peter Finke</pc:person>
        <pc:person gender="female" pid="barbaralenz">Barbara Lenz</pc:person>
        <pc:person gender="male" pid="suatyilmaz">Suat Yilmaz</pc:person>
        <pc:person gender="male" pid="onurgüntürkün">Onur Güntürkün</pc:person>
        <pc:person gender="male" pid="martinlindner">Martin Lindner</pc:person>
        <pc:person gender="male" pid="petereisenberg">Peter Eisenberg</pc:person>
        <pc:person gender="male" pid="michaelschermann">Michael Schermann</pc:person>
        <pc:person gender="male" pid="henrikmüller">Henrik Müller</pc:person>
        <pc:person gender="female" pid="antjeboetius">Antje Boetius</pc:person>
        <pc:person gender="male" pid="gunterdueck">Gunter Dueck</pc:person>
        <pc:person gender="male" pid="ferdischüth">Ferdi Schüth</pc:person>
        <pc:person gender="female" pid="claudiaeggert">Claudia Eggert</pc:person>
        <pc:person gender="female" pid="dagmarschäfer">Dagmar Schäfer</pc:person>
        <pc:person gender="female" pid="murielhelbig">Muriel Helbig</pc:person>
        <pc:person gender="male" pid="nikolauskriegeskorte">Nikolaus Kriegeskorte</pc:person>
        <pc:person gender="female" pid="ulinkarublak">Ulinka Rublack</pc:person>
        <pc:person gender="male" pid="michaelbraungart">Michael Braungart</pc:person>
        <pc:person gender="male" pid="pascalhetze">Pascal Hetze</pc:person>
        <pc:person gender="female" pid="lindabreitlauch">Linda Breitlauch</pc:person>
        <pc:person gender="male" pid="jürgenhandke">Jürgen Handke</pc:person>
        <pc:person gender="male" pid="franzjosefradermacher">Franz Josef Radermacher</pc:person>
        <pc:person gender="male" pid="klauskümmerer">Klaus Kümmerer</pc:person>
        <pc:person gender="male" pid="uweschneidewind">Uwe Schneidewind</pc:person>
        <pc:person gender="male" pid="eberhardknobloch">Eberhard Knobloch</pc:person>
        <pc:person gender="male" pid="ulrichdirnagl">Ulrich Dirnagl</pc:person>
        <pc:person gender="male" pid="hansjoosten">Hans Joosten</pc:person>
        <pc:person gender="female" pid="angelikabrandt">Angelika Brandt</pc:person>
        <pc:person gender="male" pid="andreaszick">Andreas Zick</pc:person>
        <pc:person gender="male" pid="güntherziegler">Günther Ziegler</pc:person>
        <pc:person gender="male" pid="michaelvogel">Michael Vogel</pc:person>
        <pc:person gender="female" pid="siljagraupe">Silja Graupe</pc:person>
        <pc:person gender="male" pid="ernstpeterfischer">Ernst Peter Fischer</pc:person>
        <pc:person gender="female" pid="juliaoffe">Julia Offe</pc:person>
        <pc:person gender="male" pid="pavelrichter">Pavel Richter</pc:person>
        <pc:person gender="male" pid="benjaminlahusen">Benjamin Lahusen</pc:person>
        <pc:person gender="male" pid="reinholdleinfelder">Reinhold Leinfelder</pc:person>
        <pc:person gender="female" pid="claudiahornberg">Claudia Hornberg</pc:person>
        <pc:person gender="female" pid="monikatrümper">Monika Trümper</pc:person>
        <pc:person gender="male" pid="jörnloviscach">Jörn Loviscach</pc:person>
        <pc:person gender="female" pid="lisarosa">Lisa Rosa</pc:person>
        <pc:person gender="male" pid="ralfstockmann">Ralf Stockmann</pc:person>
        <pc:person gender="female" pid="lyndalroper">Lyndal Roper</pc:person>
        <pc:person gender="male" pid="jürgentautz">Jürgen Tautz</pc:person>
        <pc:person gender="male" pid="stefankröpelin">Stefan Kröpelin</pc:person>
        <pc:person gender="male" pid="christophcorves">Christoph Corves</pc:person>
        <pc:person gender="male" pid="jöranmuußmerholz">Jöran Muußmerholz</pc:person>
        <pc:person gender="male" pid="hannshatt">Hanns Hatt</pc:person>
        <pc:person gender="female" pid="carolinbock">Carolin Bock</pc:person>
        <pc:person gender="female" pid="andreaniehaus">Andrea Niehaus</pc:person>
        <pc:person gender="male" pid="volkerquaschning">Volker Quaschning</pc:person>
        <pc:person gender="male" pid="jochenrabe">Jochen Rabe</pc:person>
        <pc:person gender="male" pid="haraldlesch">Harald Lesch</pc:person>
        <pc:person gender="male" pid="sebastiankuhn">Sebastian Kuhn</pc:person>
        <pc:person gender="male" pid="manfredniekisch">Manfred Niekisch</pc:person>
        <pc:person gender="male" pid="christopherzimmermann">Christopher Zimmermann</pc:person>
        <pc:person gender="male" pid="philippewampfler">Philippe Wampfler</pc:person>
        <pc:person gender="male" pid="stefanrahmstorf">Stefan Rahmstorf</pc:person>
        <pc:person gender="female" pid="julespecht">Jule Specht</pc:person>
        <pc:person gender="female" pid="isabelrink">Isabel Rink</pc:person>
        <pc:person gender="male" pid="ingosass">Ingo Sass</pc:person>
        <pc:person gender="male" pid="robertranisch">Robert Ranisch</pc:person>
        <pc:person gender="female" pid="anitagohdes">Anita Gohdes</pc:person>
        <pc:person gender="male" pid="gerdgigerenzer">Gerd Gigerenzer</pc:person>
        <pc:person gender="female" pid="alinakokoschka">Alina Kokoschka</pc:person>
        <pc:person gender="male" pid="oliverparodi">Oliver Parodi</pc:person>
        <pc:person gender="male" pid="justushaukap">Justus Haukap</pc:person>
        <pc:person gender="male" pid="peterpurgathofer">Peter Purgathofer</pc:person>
    </pc:persons>
<pc:episode date="2019-10-01T11:00:00" duration="01:53:23" episode="72" title="Verantwortung in der Informatik" url="https://forschergeist.de/podcast/fg072-verantwortung-in-der-informatik/">
        <pc:contributor pid="timpritlove" role="host"/>
        <pc:contributor pid="peterpurgathofer" role="guest"/>
        <pc:chapter duration="00:42" number="1" title="Intro"/>
        <pc:chapter duration="00:46" number="2" title="Begrüßung"/>
        <pc:chapter duration="08:26" number="3" title="Peter Purgathofer"/>
        <pc:chapter duration="09:26" number="4" title="Ethik und Moral in der Informatik"/>
        <pc:chapter duration="06:41" number="5" title="Entscheidung und Verantwortung"/>
        <pc:chapter duration="11:22" number="6" title="Denkweisen in der Informatik"/>
        <pc:chapter duration="00:55" number="7" title="Strukturierung des Kurses"/>
        <pc:chapter duration="05:31" number="8" title="Pre-Scientific Thinking"/>
        <pc:chapter duration="04:15" number="9" title="Scientific Thinking"/>
        <pc:chapter duration="06:01" number="10" title="Mathematical Thinking"/>
        <pc:chapter duration="07:35" number="11" title="Computational Thinking"/>
        <pc:chapter duration="09:57" number="12" title="Design Thinking"/>
        <pc:chapter duration="10:20" number="13" title="Critical Thinking und Diversity"/>
        <pc:chapter duration="05:15" number="14" title="Responsible Thinking"/>
        <pc:chapter duration="04:00" number="15" title="Creative Thinking"/>
        <pc:chapter duration="02:18" number="16" title="Economical Thinking"/>
        <pc:chapter duration="04:07" number="17" title="Criminal Thinking"/>
        <pc:chapter duration="02:07" number="18" title="Denkweisen für die Wissenschaft"/>
        <pc:chapter duration="11:45" number="19" title="Der Reifegrad der Informatik"/>
        <pc:chapter duration="01:43" number="20" title="Ausklang"/>
        <pt:transcript version="0.1" xmlns:pt="https://purl.org/net/hbuschme/teaching/2019ws-infostruk/podcast-transcript/0.1">
            <pt:segment contributor="timpritlove" end="00:00:49.300" start="00:00:43.101">Hallo und herzlich willkommen zu Forschergeist, dem Podcast des Stifterverbands für die deutsche Wissenschaft.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:00:57.600" start="00:00:49.301">Mein Name ist Tim Pritlove und ich begrüße alle zu Ausgabe Nummer 72 hier in unserer Gesprächsreihe rund um Wissenschaft,</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:04.300" start="00:00:57.601">wissenschaftliche Fragen, manchmal geht es um Wissenschaft, manchmal geht es auch um die Metafragen der Wissenschaft.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:08.100" start="00:01:04.301">Und ein solches Thema erwartet uns heute.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:17.000" start="00:01:08.101">Dafür bin ich mal wieder ein wenig gereist, konkret bin ich nach Wien gefahren an die TU Wien.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:26.400" start="00:01:17.001">Dort sitze ich jetzt im Institut für Visual Computing and Human-Centered Technology und begrüße meinen Gesprächspartner, nämlich den Peter, Peter Purgathofer.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:27.300" start="00:01:26.401">Schönen guten Tag.</pt:segment>
            <pt:segment contributor="peterpurgathofer" end="00:01:29.200" start="00:01:27.301">Hallo.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:34.100" start="00:01:29.201">Peter, wir kennen uns schon eine Weile, du bist schon ganz schön lange hier oder?</pt:segment>
            <pt:segment contributor="peterpurgathofer" end="00:01:39.500" start="00:01:34.101">Ja, ich habe vor, glaube ich, zwei Jahren meine 25-jährige Jubiläumszahlung bekommen.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:41.100" start="00:01:39.501">Guck an.</pt:segment>
            <pt:segment contributor="peterpurgathofer" end="00:01:45.000" start="00:01:41.101">Auch so eine Art Bookmark, die man im Leben seiner Tätigkeit hat.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:50.500" start="00:01:45.001">Ja. Und konkret bist du aber schon immer der Informatik zugehörig gewesen.</pt:segment>
            <pt:segment contributor="peterpurgathofer" end="00:01:50.600" start="00:01:50.501">Immer.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:52.400" start="00:01:50.601">Immer.</pt:segment>
<pc:episode date="2019-09-05T14:48:00" duration="02:29:05" episode="71" title="Wirtschaft und Wettbewerb" url="https://forschergeist.de/podcast/fg071-wirtschaft-und-wettbewerb/">
        <pc:contributor pid="timpritlove" role="host"/>
        <pc:contributor pid="justushaucap" role="guest"/>
        <pc:chapter duration="00:42" number="1" title="Intro"/>
        <pc:chapter duration="01:04" number="2" title="Begrüßung"/>
        <pc:chapter duration="12:28" number="3" title="Persönlicher Hintergrund"/>
        <pc:chapter duration="02:36" number="4" title="Instutute of Competition Economics (DICE)"/>
        <pc:chapter duration="04:57" number="5" title="Monopolkommission"/>
        <pc:chapter duration="11:10" number="6" title="Unser Wirtschaftssystem"/>
        <pc:chapter duration="12:02" number="7" title="Marktversagen"/>
        <pc:chapter duration="07:33" number="8" title="Liberalisierungen und natürliche Monopole"/>
        <pc:chapter duration="08:41" number="9" title="Öffentliche Straßen"/>
        <pc:chapter duration="05:22" number="10" title="Lenkungsfunktionen"/>
        <pc:chapter duration="12:41" number="11" title="Telekommunikationsmarkt"/>
        <pc:chapter duration="04:58" number="12" title="Trägheit der Entwicklung"/>
        <pc:chapter duration="07:14" number="13" title="Soziale Umverteilung"/>
        <pc:chapter duration="10:22" number="14" title="Erneuerbare-Energien-Gesetz"/>
        <pc:chapter duration="12:59" number="15" title="Drogenlegalisierung"/>
        <pc:chapter duration="11:39" number="16" title="Medienmarkt und öffentlicher Rundfunk"/>
        <pc:chapter duration="15:26" number="17" title="Digitalwirtschaft und neue Monopole"/>
        <pc:chapter duration="02:30" number="18" title="Zukünftige Baustellen"/>
        <pc:chapter duration="03:21" number="19" title="Fortschritte in der Wirtschaftsforschung"/>
        <pc:chapter duration="01:12" number="20" title="Ausklang"/>
        <pt:transcript version="0.1" xmlns:pt="https://purl.org/net/hbuschme/teaching/2019ws-infostruk/podcast-transcript/0.1">
            <pt:segment contributor="timpritlove" end="00:00:49.000" start="00:00:43.401">Hallo und herzlich willkommen zu Forschergeist, dem Podcast des Stifterverbands für die deutsche Wissenschaft.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:00.700" start="00:00:49.001">Mein Name ist Tim Pritlove und ich begrüße alle zu Ausgabe Nummer 71 unserer immer weiter voranschreitenden Gesprächsserie über alle möglichen Einblicke,</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:07.400" start="00:01:00.701">die uns die Wissenschaft bietet oder die wir vielleicht auch selbst in die Wissenschaft hier gewinnen wollen.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:15.400" start="00:01:07.401">Und nun haben wir ja schon einen ziemlich breites Bouquet an Themen abgearbeitet hier in den letzten fünf Jahren.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:19.100" start="00:01:15.401">Eins ist ein bisschen zu kurz gekommen, die Wirtschaft.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:29.200" start="00:01:19.101">Was nicht bedeutet, dass das uninteressant ist und vor allem ist ja auch die Erkenntnis, dass Wirtschaft nicht nur stattfindet und ein tägliches politisches Thema ist,</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:33.900" start="00:01:29.201">sondern dass daran auch geforscht wird, auch nochmal ganz interessant.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:41.500" start="00:01:33.901">Und um darüber ein wenig zu sprechen, insbesondere über die Fragen des Wettbewerbs in der Wirtschaft, begrüßte ich zunächst einmal meinen Gesprächspartner,</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:43.500" start="00:01:41.501">nämlich Justus Haukap, schönen guten Tag.</pt:segment>
            <pt:segment contributor="justushaucap" end="00:01:43.700" start="00:01:43.501">Ja, guten Tag.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:47.200" start="00:01:43.701">Herzlich willkommen bei Forschergeist.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:01:57.700" start="00:01:47.201">Ja, Herr Haukap, sie sind in Düsseldorf, dort als Wirtschaftswissenschaftler an der Heinrich-Heine-Universität aktiv.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:02:05.300" start="00:01:57.701">Dort auch mittlerweile Dekan der wirtschaftswissenschaftlichen Fakultät, wenn ich das richtig sehe.</pt:segment>
            <pt:segment contributor="justushaucap" end="00:02:05.900" start="00:02:05.301">Gewesen.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:02:07.700" start="00:02:05.901">Gewesen, ist schon wieder vorbei?</pt:segment>
            <pt:segment contributor="justushaucap" end="00:02:08.000" start="00:02:07.701">Genau.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:02:12.500" start="00:02:08.001">Ach okay, gut na dann wissen wir es jetzt.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:02:15.700" start="00:02:12.501">Aber das wird ja sicherlich auch einen gewissen Vorlauf gehabt haben.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:02:19.200" start="00:02:15.701">Wie interessiert man sich denn eigentlich für Wirtschaft?</pt:segment>
            <pt:segment contributor="timpritlove" end="00:02:22.800" start="00:02:19.201">Weil ich fand das ja eigentlich ein bisschen unspannend.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:02:25.900" start="00:02:22.801">Ich weiß nicht genau warum, aber war so.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:02:29.400" start="00:02:25.901">Und ich dachte mir immer so, ich mache lieber Computer.</pt:segment>
            <pt:segment contributor="timpritlove" end="00:02:37.500" start="00:02:29.401">Gibt es da irgendwie so einen Auslöser oder war das so, entweder was mit Tieren oder was mit Wirtschaft?</pt:segment>
            <pt:segment contributor="justushaucap" end="00:02:38.400" start="00:02:37.501">Irgendwas mit Medien.</pt:segment>
</pc:podcast>

My XSL

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
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" 
exclude-result-prefixes="pc pt">
<xsl:output method="html"/>

<xsl:key name="person" match="pc:person" use="@pid"/>
<xsl:key name="segment" match="pt:segment" use="@contributor"/>

<xsl:template match="/pc:podcast">
    <html>
        <body>
            <h1>Your title</h1>
            <xsl:apply-templates select="pc:episode/pc:contributor" />
        </body>
    </html>
</xsl:template>

<xsl:template match="pc:contributor">
    <p>
        <xsl:text>Episode </xsl:text>
        <xsl:value-of select="../@episode"/>
        <xsl:text>: </xsl:text>
        <xsl:value-of select="key('person', @pid)"/>
        <xsl:text> Total time: </xsl:text>
        <xsl:call-template name="sum-durations">
            <xsl:with-param name="nodes" select="key('segment', @pid)"/>
        </xsl:call-template>
        <xsl:text> seconds</xsl:text>
    </p>
    <p>
        <xsl:text>Total time</xsl:text>
        <xsl:call-template name="milliseconds-to-time">
                  <xsl:with-param name="milliseconds" select="nodes"/>
        </xsl:call-template>    


    </p>
</xsl:template>

<xsl:template name="sum-durations">
    <xsl:param name="nodes"/>
    <xsl:param name="sum" select="0"/>
    <xsl:choose>
        <xsl:when test="count($nodes)">
            <xsl:variable name="node" select="$nodes[1]" />
            <xsl:variable name="start">
                <xsl:call-template name="time2sec">
                    <xsl:with-param name="time" select="$node/@start"/>
                </xsl:call-template>
            </xsl:variable>
            <xsl:variable name="end">
                <xsl:call-template name="time2sec">
                    <xsl:with-param name="time" select="$node/@end"/>
                </xsl:call-template>
            </xsl:variable>
            <xsl:call-template name="sum-durations">
                <xsl:with-param name="nodes" select="$nodes[position() > 1]"/>
                <xsl:with-param name="sum" select="$sum + $end - $start"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$sum"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template name="time2sec">
    <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:value-of select="3600*$h + 60*$m + $s"/>
</xsl:template>

<xsl:template name="milliseconds-to-time">
    <xsl:param name="milliseconds"/>
    <xsl:variable name="h" select="floor($milliseconds div 3600000)"/>
    <xsl:variable name="m" select="floor($milliseconds div 60000) mod 60"/>
    <xsl:variable name="s" select="$milliseconds mod 60000 div 1000"/>
    <xsl:value-of select="format-number($h, '00')" />
    <xsl:value-of select="format-number($m, ':00')" />
    <xsl:value-of select="format-number($s, ':00.###')" />
</xsl:template>

</xsl:stylesheet>

Desired Output should be something like this:

Epsiode 72: Peter Burghofer: ... Minutes or: 00:45:22.233
Episode 72: Tim Pritlove ... Minutes or: 00:23:12.675 
Episode lenght of Episode 72: 01:53:23

What's the best way to handle/solve this problem? Any advice/suggestions? Can you provide me an example of how it should look like?

ASCIIIIIII
  • 21
  • 5
  • When you post a not well-formed XML input, we have nothing to test our answer with. So we need to either waste our time correcting your input or post an untested answer. – michael.hor257k Feb 03 '20 at 11:51
  • I have rolled your question back to what it was when I have answered it. If you have additional questions, please post them separately (and make sure we can understand them). – michael.hor257k Feb 03 '20 at 13:03

1 Answers1

0

I want the sum of the "speech share"

There is no "speech share" in the XML you show. I am assuming you meant the total time of each contributor's segments. This is not trivial to do in XSLT 1.0.

First, you need to compute the individual pt:segment durations. For this, you need to convert the start and end times to seconds (or some other common unit) so that you can subtract them. And you need to convert the results to a node-set so that they can be summed.

Try something like the following:

XSLT 1.0 (+ EXSLT)

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
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:exsl="http://exslt.org/common"
exclude-result-prefixes="pc pt"
extension-element-prefixes="exsl">
<xsl:output method="html"/>

<xsl:key name="person" match="pc:person" use="@pid"/>
<xsl:key name="segment" match="pt:segment" use="@contributor"/>

<xsl:template match="/pc:podcast">
    <html>
        <body>
            <h1>Your title</h1>
            <xsl:apply-templates select="pc:episode/pc:contributor" />
        </body>
    </html>
</xsl:template>

<xsl:template match="pc:contributor">
    <p>
        <xsl:text>Episode </xsl:text>
        <xsl:value-of select="../@episode"/>
        <xsl:text>: </xsl:text>
        <xsl:value-of select="key('person', @pid)"/>
        <xsl:text> Total time: </xsl:text>
        <xsl:variable name="durations">
            <xsl:for-each select="key('segment', @pid)">
                <xsl:variable name="start">
                    <xsl:call-template name="time2sec">
                        <xsl:with-param name="time" select="@start"/>
                    </xsl:call-template>
                </xsl:variable>
                <xsl:variable name="end">
                    <xsl:call-template name="time2sec">
                        <xsl:with-param name="time" select="@end"/>
                    </xsl:call-template>
                </xsl:variable>
                <duration>
                    <xsl:value-of select="$end - $start"/>
                </duration>
            </xsl:for-each>
        </xsl:variable>
        <xsl:value-of select="sum(exsl:node-set($durations)/duration)"/>
        <xsl:text> seconds</xsl:text>
    </p>
</xsl:template>

<xsl:template name="time2sec">
    <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:value-of select="3600*$h + 60*$m + $s"/>
</xsl:template>

</xsl:stylesheet>

Added:

To do the same thing in pure XSLT 1.0, with no extension functions, try:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
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" 
exclude-result-prefixes="pc pt">
<xsl:output method="html"/>

<xsl:key name="person" match="pc:person" use="@pid"/>
<xsl:key name="segment" match="pt:segment" use="@contributor"/>

<xsl:template match="/pc:podcast">
    <html>
        <body>
            <h1>Your title</h1>
            <xsl:apply-templates select="pc:episode/pc:contributor" />
        </body>
    </html>
</xsl:template>

<xsl:template match="pc:contributor">
    <p>
        <xsl:text>Episode </xsl:text>
        <xsl:value-of select="../@episode"/>
        <xsl:text>: </xsl:text>
        <xsl:value-of select="key('person', @pid)"/>
        <xsl:text> Total time: </xsl:text>
        <xsl:call-template name="sum-durations">
            <xsl:with-param name="nodes" select="key('segment', @pid)"/>
        </xsl:call-template>
        <xsl:text> seconds</xsl:text>
    </p>
</xsl:template>

<xsl:template name="sum-durations">
    <xsl:param name="nodes"/>
    <xsl:param name="sum" select="0"/>
    <xsl:choose>
        <xsl:when test="count($nodes)">
            <xsl:variable name="node" select="$nodes[1]" />
            <xsl:variable name="start">
                <xsl:call-template name="time2sec">
                    <xsl:with-param name="time" select="$node/@start"/>
                </xsl:call-template>
            </xsl:variable>
            <xsl:variable name="end">
                <xsl:call-template name="time2sec">
                    <xsl:with-param name="time" select="$node/@end"/>
                </xsl:call-template>
            </xsl:variable>
            <xsl:call-template name="sum-durations">
                <xsl:with-param name="nodes" select="$nodes[position() > 1]"/>
                <xsl:with-param name="sum" select="$sum + $end - $start"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$sum"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template name="time2sec">
    <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:value-of select="3600*$h + 60*$m + $s"/>
</xsl:template>

</xsl:stylesheet>
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • I've tried your solution but I'am getting an error: "Unregistered function". – ASCIIIIIII Feb 03 '20 at 12:03
  • Which XSLT processor are you using? – michael.hor257k Feb 03 '20 at 12:05
  • I'm using the software "XML Copy Editor". I think it's using Saxon. – ASCIIIIIII Feb 03 '20 at 12:31
  • Please find out - see here how: https://stackoverflow.com/a/25245033/3016153 Is that the exact error message or is there more? – michael.hor257k Feb 03 '20 at 12:39
  • Processor is: libxslt and Version is: 1.0 The exact error message is: "Transformation not possible: Error at line 0: Unregistered function" – ASCIIIIIII Feb 03 '20 at 12:49
  • This is very strange. The libxslt processor certainly supports the EXSLT `node-set()` extension function I have used. And there is no function on line 0. I have added a "pure" XSLT 1.0 solution to my answer. If that doesn't work for you, then I don't know what will. – michael.hor257k Feb 03 '20 at 12:57
  • Okay, it seems to work so far. Now can can you still show me how to calculate the sum of the durations values of the elements pc:chapter for all pc:episodes? So for example 00:41+00:10= 00:51... – ASCIIIIIII Feb 03 '20 at 13:12
  • The same way: convert them to seconds (or milliseconds), sum the results and convert the sum back to time. – michael.hor257k Feb 03 '20 at 13:34
  • Short update: I have tested your solution but now I'm getting the following output: Your title Episode 72: Tim Pritlove Total time: NaN seconds Episode 72: Peter Purgathofer Total time: NaN seconds – ASCIIIIIII Feb 03 '20 at 13:40
  • I am afraid I cannot help you with a problem I cannot reproduce. I have tested my answer using a corrected input. You can see it working here: https://xsltfiddle.liberty-development.net/bwe3bY – michael.hor257k Feb 03 '20 at 14:41
  • Thanks anyway. I think the problem is related to the software. – ASCIIIIIII Feb 03 '20 at 15:15