]> granicus.if.org Git - docbook-dsssl/commitdiff
Fix bugs #1305 and 1353: support multiple videodata/audiodata using the source elemen...
authorBob Stayton <bobs@sagehill.net>
Tue, 7 Jul 2015 17:32:03 +0000 (17:32 +0000)
committerBob Stayton <bobs@sagehill.net>
Tue, 7 Jul 2015 17:32:03 +0000 (17:32 +0000)
xsl/xhtml5/html5-element-mods.xsl

index b9a89dc4fffb6ff3fd161386f2333ed1bf3a2414..cf533ff2617b8c93e4c021c1c2bb7241665aef93 100644 (file)
@@ -5,16 +5,17 @@
 ]>
 <xsl:stylesheet 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
-  xmlns:exsl="http://exslt.org/common"
+  xmlns:d="http://docbook.org/ns/docbook"
+xmlns:exsl="http://exslt.org/common"
   xmlns="http://www.w3.org/1999/xhtml"
   xmlns:stbl="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.Table"
   xmlns:xtbl="xalan://com.nwalsh.xalan.Table"
   xmlns:lxslt="http://xml.apache.org/xslt"
   xmlns:ptbl="http://nwalsh.com/xslt/ext/xsltproc/python/Table"
-  exclude-result-prefixes="exsl stbl xtbl lxslt ptbl"
+  exclude-result-prefixes="exsl stbl xtbl lxslt ptbl d"
   version="1.0">
 
-<!-- $Id: html5-element-mods.xsl,v 1.2 2011-09-18 17:47:28 bobs Exp $ -->
+<!-- $I html5-element-mods.xsl,v 1.2 2011-09-18 17:47:28 bobs Exp $ -->
 
 <!--==============================================================-->
 <!--  DocBook XSL Parameter settings                              -->
   </li>
 </xsl:template>
 
-<xsl:template match="audiodata">
+<!-- output html5 video and source elements -->
+<xsl:template match="videoobject">
+  <video>
+    <xsl:call-template name="common.html.attributes"/>
+    <xsl:call-template name="video.poster"/>
+    <!-- copy videodata attributes from first videodata child only -->
+    <xsl:apply-templates select="videodata[1]/@*" mode="video.attribute"/>
+    <xsl:apply-templates select="videodata[1]/multimediaparam" mode="video.attribute"/>
+
+    <!-- generate <source> element for each videodata element -->
+    <xsl:apply-templates select="videodata"/>
+
+    <!-- add any fallback content -->
+    <xsl:call-template name="video.fallback"/>
+
+  </video>
+</xsl:template>
+
+<!-- output html5 audio and source elements -->
+<xsl:template match="audioobject">
+  <audio>
+    <xsl:call-template name="common.html.attributes"/>
+
+    <!-- copy audiodata attributes from first audiodata child only -->
+    <xsl:apply-templates select="audiodata[1]/@*" mode="audio.attribute"/>
+    <xsl:apply-templates select="audiodata[1]/multimediaparam" mode="audio.attribute"/>
+
+    <!-- generate <source> element for each videodata element -->
+    <xsl:apply-templates select="audiodata"/>
+
+    <!-- add any fallback content -->
+    <xsl:call-template name="audio.fallback"/>
+
+  </audio>
+</xsl:template>
+
+<xsl:template match="videodata">
+
   <xsl:variable name="filename">
     <xsl:call-template name="mediaobject.filename">
-      <xsl:with-param name="object" select=".."/>
+      <!-- Call it with the videodata as the object -->
+      <xsl:with-param name="object" select="."/>
     </xsl:call-template>
   </xsl:variable>
 
-  <audio>
+  <source>
     <xsl:call-template name="common.html.attributes"/>
 
     <xsl:attribute name="src">
       <xsl:value-of select="$filename"/>
     </xsl:attribute>
 
-    <xsl:apply-templates select="@*"/>
-    <xsl:apply-templates select="../multimediaparam"/>
+    <xsl:apply-templates select="@format" mode="source.attribute"/>
 
-    <!-- add any fallback content -->
-    <xsl:call-template name="audio.fallback"/>
-  </audio>
+    <xsl:apply-templates select="multimediaparam" mode="source.attribute"/>
+    
+  </source>
 </xsl:template>
 
-<!-- generate <video> element for html5 -->
-<xsl:template match="videodata">
+<xsl:template match="audiodata">
+
   <xsl:variable name="filename">
     <xsl:call-template name="mediaobject.filename">
-      <xsl:with-param name="object" select=".."/>
+      <!-- Call it with the videodata as the object -->
+      <xsl:with-param name="object" select="."/>
     </xsl:call-template>
   </xsl:variable>
 
-  <video>
+  <source>
     <xsl:call-template name="common.html.attributes"/>
 
     <xsl:attribute name="src">
       <xsl:value-of select="$filename"/>
     </xsl:attribute>
 
-    <xsl:call-template name="video.poster"/>
+    <xsl:apply-templates select="@format" mode="source.attribute"/>
 
-    <xsl:apply-templates select="@*[local-name() != 'fileref']"/>
-    <xsl:apply-templates select="../multimediaparam"/>
+    <xsl:apply-templates select="multimediaparam" mode="source.attribute"/>
     
-    <!-- add any fallback content -->
-    <xsl:call-template name="video.fallback"/>
-  </video>
+  </source>
+</xsl:template>
+
+<!-- attributes handled in modes, so default is off -->
+<xsl:template match="@*" mode="source.attribute"/>
+<xsl:template match="@*" mode="video.attribute"/>
+<xsl:template match="@*" mode="audio.attribute"/>
+
+<xsl:template match="@format" mode="source.attribute">
+  <xsl:attribute name="type">
+    <xsl:value-of select="normalize-space(.)"/>
+  </xsl:attribute>
 </xsl:template>
 
 <!-- use only an imageobject with @role = 'poster' -->
 <xsl:template name="video.poster">
-  <xsl:variable name="imageobject" select="../../imageobject[@role = 'poster'][1]"/>
+  <!-- context is videoobject -->
+  <xsl:variable name="imageobject" 
+                select="../../imageobject[@role = 'poster'][1] | 
+                           ../imageobject[@role = 'poster'][1]"/>
   <xsl:if test="$imageobject">
     <xsl:attribute name="poster">
       <xsl:value-of select="$imageobject/imagedata/@fileref"/>
   </xsl:if>
 </xsl:template>
 
-<xsl:template match="videodata/@fileref">
-  <!-- already handled by videodata template -->
+<xsl:template match="videodata/@fileref" mode="source.attribute">
+  <!-- process in normal mode -->
+  <xsl:apply-templates select="."/>
 </xsl:template>
 
-<xsl:template match="audiodata/@fileref">
-  <!-- already handled by audiodata template -->
-</xsl:template>
+<xsl:template match="videodata/@fileref" mode="video.attribute"/>
 
-<xsl:template match="videodata/@contentwidth">
-  <xsl:attribute name="width">
-    <xsl:value-of select="."/>
-  </xsl:attribute>
+<xsl:template match="audiodata/@fileref" mode="source.attribute">
+  <!-- process in normal mode -->
+  <xsl:apply-templates select="."/>
 </xsl:template>
 
-<xsl:template match="videodata/@contentdepth">
-  <xsl:attribute name="height">
+<xsl:template match="audiodata/@fileref" mode="audio.attribute"/>
+
+<xsl:template match="videodata/@contentwidth | videodata/@width" 
+              mode="video.attribute">
+  <xsl:attribute name="width">
     <xsl:value-of select="."/>
   </xsl:attribute>
 </xsl:template>
 
-<xsl:template match="videodata/@depth">
+<xsl:template match="videodata/@contentdepth | videodata/@depth"
+              mode="video.attribute">
   <xsl:attribute name="height">
     <xsl:value-of select="."/>
   </xsl:attribute>
 </xsl:template>
 
-<!-- pass through these attributes -->
-<xsl:template match="videodata/@autoplay |
-                     videodata/@controls |
-                     audiodata/@autoplay |
-                     audiodata/@controls">
-  <xsl:copy-of select="."/>
-</xsl:template>
+<xsl:template match="multimediaparam" mode="source.attribute"/>
+<xsl:template match="multimediaparam" mode="video.attribute"/>
 
-<xsl:template match="videodata/@*" priority="-1">
-  <!-- Do nothing with the rest of the attributes -->
+<xsl:template match="multimediaparam[@name = 'autoplay' or
+                                       @name = 'controls' or
+                                       @name = 'height' or
+                                       @name = 'loop' or
+                                       @name = 'muted' or
+                                       @name = 'preload' or
+                                       @name = 'width']"
+             mode="video.attribute">
+  <xsl:call-template name="process.multimediaparam">
+    <xsl:with-param name="object" select=".."/>
+    <xsl:with-param name="param.name" select="@name"/>
+    <xsl:with-param name="param.value" select="@value"/>
+  </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="audiodata/@*" priority="-1">
-  <!-- Do nothing with the rest of the attributes -->
+<xsl:template match="multimediaparam[@name = 'autoplay' or
+                                       @name = 'controls' or
+                                       @name = 'loop' or
+                                       @name = 'muted' or
+                                       @name = 'preload']"
+             mode="audio.attribute">
+  <xsl:call-template name="process.multimediaparam">
+    <xsl:with-param name="object" select=".."/>
+    <xsl:with-param name="param.name" select="@name"/>
+    <xsl:with-param name="param.value" select="@value"/>
+  </xsl:call-template>
 </xsl:template>
 
-<xsl:template match="multimediaparam">
+<xsl:template match="multimediaparam[not(@name = 'autoplay' or
+                                       @name = 'controls' or
+                                       @name = 'height' or
+                                       @name = 'loop' or
+                                       @name = 'muted' or
+                                       @name = 'preload' or
+                                       @name = 'width')]"
+             mode="source.attribute">
   <xsl:call-template name="process.multimediaparam">
     <xsl:with-param name="object" select=".."/>
     <xsl:with-param name="param.name" select="@name"/>
   </xsl:call-template>
 </xsl:template>
 
+
 <!-- Determines the best value of a media attribute from the
   attributes and multimediaparam elements -->
 <xsl:template name="process.multimediaparam">
 </xsl:template>
 
 <xsl:template name="video.fallback">
-  <xsl:param name="videodata" select="."/>
-  <xsl:variable name="textobject" select="$videodata/../../textobject"/>
+  <xsl:param name="videoobject" select="."/>
+  <xsl:variable name="textobject" select="$videoobject/../textobject"/>
+
+  <xsl:choose>
+    <xsl:when test="$textobject">
+      <xsl:apply-templates select="$textobject" mode="fallback"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:call-template name="video.fallback.text"/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
 
-  <xsl:apply-templates select="$textobject" mode="fallback"/>
+<xsl:template name="video.fallback.text">
+  <xsl:call-template name="gentext">
+    <xsl:with-param name="key" select="'video-unsupported'"/>
+  </xsl:call-template>
 </xsl:template>
 
 <xsl:template name="audio.fallback">
   <xsl:param name="audiodata" select="."/>
   <xsl:variable name="textobject" select="$audiodata/../../textobject"/>
 
-  <xsl:apply-templates select="$textobject" mode="fallback"/>
+  <xsl:choose>
+    <xsl:when test="$textobject">
+      <xsl:apply-templates select="$textobject" mode="fallback"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:call-template name="audio.fallback.text"/>
+    </xsl:otherwise>
+  </xsl:choose>
+
+</xsl:template>
+
+<xsl:template name="audio.fallback.text">
+  <xsl:call-template name="gentext">
+    <xsl:with-param name="key" select="'audio-unsupported'"/>
+  </xsl:call-template>
 </xsl:template>
 
 <xsl:template match="textobject" mode="fallback">