<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:pf="http://www.daisy.org/ns/pipeline/functions" xmlns:c="http://www.w3.org/ns/xproc-step" version="2.0" xpath-default-namespace="" exclude-result-prefixes="#all"> <xsl:import href="http://www.daisy.org/pipeline/modules/file-utils/library.xsl"/> <xsl:import href="http://www.daisy.org/pipeline/modules/smil-utils/clock-functions.xsl"/> <xsl:param name="context" as="document-node()*"/> <xsl:template match="/*"> <c:result> <xsl:apply-templates select="*"/> </c:result> </xsl:template> <xsl:template match="*:smil"> <smil> <xsl:variable name="base" select="base-uri(.)"/> <xsl:attribute name="xml:base" select="$base"/> <xsl:variable name="meta-duration" select="head/meta[@name='ncc:timeInThisSmil']/string(@content)"/> <xsl:variable name="meta-duration" select="if ($meta-duration) then pf:smil-clock-value-to-seconds($meta-duration) else 0"/> <xsl:choose> <xsl:when test=".//ref"> <xsl:attribute name="is-master" select="'true'"/> <xsl:variable name="duration" as="xs:decimal*"> <xsl:for-each select=".//ref"> <xsl:variable name="src" as="xs:string" select="pf:normalize-uri(@src)"/> <xsl:variable name="src" as="xs:string*" select="pf:tokenize-uri($src)"/> <xsl:variable name="fragment" as="xs:string?" select="$src[5]"/> <xsl:variable name="file" as="xs:string" select="pf:recompose-uri($src[position()<5])"/> <xsl:variable name="file" as="xs:anyURI" select="resolve-uri($file,$base)"/> <xsl:variable name="file" as="document-node()?" select="$context[base-uri(/)=$file]"/> <xsl:choose> <xsl:when test="exists($file)"> <xsl:choose> <xsl:when test="exists($fragment)"> <xsl:variable name="fragment" as="element()" select="$file//*[@id=$fragment]"/> <xsl:choose> <xsl:when test="exists($fragment)"> <xsl:sequence select="pf:smil-total-seconds($file/*)"/> </xsl:when> <xsl:otherwise> <xsl:message select="concat('ref points to a non-existing SMIL element: ',@src)"/> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:sequence select="pf:smil-total-seconds($file/*)"/> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:message select="concat('ref points to a non-existing SMIL file: ',@src)"/> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:variable> <xsl:attribute name="calculated-duration" select="sum($duration)"/> </xsl:when> <xsl:otherwise> <xsl:attribute name="calculated-duration" select="pf:smil-total-seconds(.)"/> </xsl:otherwise> </xsl:choose> <xsl:for-each select="body//audio[(@clip-begin and not(@clip-end)) or (not(@clip-begin) and @clip-end)]"> <xsl:message select="concat('audio clip is missing a ', (if (@clip-begin) then 'clip-end' else 'clip-begin'), ' attribute (par id: ', parent::par/@id, ')')"/> </xsl:for-each> <xsl:attribute name="meta-duration" select="$meta-duration"/> <xsl:variable name="meta-totalTime" select="head/meta[@name='ncc:totalElapsedTime'] /string(@content)"/> <xsl:attribute name="meta-totalTime" select="if ($meta-totalTime) then pf:smil-clock-value-to-seconds($meta-totalTime) else 0"/> </smil> </xsl:template> </xsl:stylesheet>