]> granicus.if.org Git - docbook-dsssl/commitdiff
fixed figure captions and associated figure metadata
authorSteve Ball <balls@users.sourceforge.net>
Thu, 10 Jul 2008 07:44:26 +0000 (07:44 +0000)
committerSteve Ball <balls@users.sourceforge.net>
Thu, 10 Jul 2008 07:44:26 +0000 (07:44 +0000)
xsl/roundtrip/blocks2dbk.xsl

index da48bfdef359cbfe489a3af8868f887a0b711f05..2988e096c2f9478b5cf5ad58b0bbe8a192fa96cf 100644 (file)
     <xsl:variable name='table'
                  select='preceding-sibling::dbk:informaltable[1]'/>
     <xsl:variable name='figure'
-                 select='preceding-sibling::dbk:para[dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = ""][1]'/>
+                 select='preceding-sibling::dbk:para[@rnd:style = "informalfigure-imagedata" or (dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = "")][1]'/>
     <xsl:variable name='caption'
                  select='following-sibling::dbk:para[@rnd:style = "caption" or @rnd:style = "Caption"]'/>
 
                      following-sibling::*[1][self::dbk:informaltable]'/>
       <xsl:when test='$suppress and
                      @rnd:style = "figure-title" and
-                     following-sibling::*[1][self::dbk:para][dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = ""]'/>
+                     following-sibling::*[1][self::dbk:para][@rnd:style = "informalfigure-imagedata" or (dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = "")]'/>
       <xsl:when test='$suppress and
                      (@rnd:style = "caption" or @rnd:style = "Caption") and
                      (preceding-sibling::*[self::dbk:informaltable] or
-                     preceding-sibling::*[self::dbk:para][dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = ""])'/>
+                     preceding-sibling::*[self::dbk:para][@rnd:style = "informalfigure-imagedata" or (dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = "")])'/>
 
       <xsl:when test='$suppress and
                      $table and
       <xsl:when test='$suppress and
                      $figure and
                      $caption and
-                     generate-id($caption/preceding-sibling::dbk:para[dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = ""][1]) = generate-id($figure)'/>
+                     generate-id($caption/preceding-sibling::dbk:para[@rnd:style = "informalfigure-imagedata" or (dbk:inlinemediaobject and count(*) = 1 and normalize-space(.) = "")][1]) = generate-id($figure)'/>
 
       <!-- Ignore empty paragraphs -->
       <xsl:when test='(not(@rnd:style) or
       </xsl:when>
 
       <xsl:when test='@rnd:style = "informalfigure-imagedata"'>
+        <xsl:variable name='caption.next'
+          select='following-sibling::dbk:para[@rnd:style = "caption" or @rnd:style = "Caption"][1]'/>
+
         <xsl:choose>
           <xsl:when test='preceding-sibling::*[1][self::dbk:para][@rnd:style = "figure-title"]'>
             <dbk:figure>
                   <dbk:imagedata fileref='{.}'/>
                 </dbk:imageobject>
               </dbk:mediaobject>
-              <xsl:apply-templates select='following-sibling::*[1][self::dbk:para][@rnd:style = "caption" or @rnd:style = "Caption"]'
-                mode='rnd:caption'/>
+              <xsl:call-template name='rnd:figure-text-caption'>
+                <xsl:with-param name='caption' select='$caption.next'/>
+              </xsl:call-template>
             </dbk:figure>
           </xsl:when>
           <xsl:otherwise>
                   <dbk:imagedata fileref='{.}'/>
                 </dbk:imageobject>
               </dbk:mediaobject>
-              <xsl:apply-templates select='following-sibling::*[1][self::dbk:para][@rnd:style = "caption" or @rnd:style = "Caption"]'
-                mode='rnd:caption'/>
+              <xsl:call-template name='rnd:figure-text-caption'>
+                <xsl:with-param name='caption' select='$caption.next'/>
+              </xsl:call-template>
             </dbk:informalfigure>
           </xsl:otherwise>
         </xsl:choose>
     </xsl:choose>
   </xsl:template>
 
+  <!-- Determine if the caption belongs to the current figure.
+       If so, then process the textobject content and the caption.
+    -->
+  <xsl:template name='rnd:figure-text-caption'>
+    <xsl:param name='caption' select='/..'/>
+
+    <xsl:variable name='textobjs'
+      select='following-sibling::*[following-sibling::*[generate-id() = generate-id($caption)]]'/>
+
+    <xsl:choose>
+      <xsl:when test='not($caption)'/> <!-- nothing to do -->
+      <xsl:when test='$textobjs[self::dbk:informaltable |
+                      self::dbk:inlinemediaobject |
+                      self::dbk:para[@rnd:style = "informalfigure-imagedata" or
+                      @rnd:style = "mediaobject-imagedata"]]'/> <!-- caption belongs to something else -->
+      <xsl:otherwise>
+        <xsl:apply-templates select='$textobjs' mode='rnd:textobject'/>
+
+        <xsl:apply-templates select='$caption' mode='rnd:caption'/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
   <xsl:template match='dbk:para' mode='rnd:caption'>
     <dbk:caption>
       <xsl:call-template name='rnd:attributes'/>
     </xsl:choose>
   </xsl:template>
 
+  <xsl:template match='dbk:footnote' mode='rnd:personname'/>
   <xsl:template match='dbk:emphasis' mode='rnd:personname'>
     <xsl:choose>
       <xsl:when test='@rnd:style = "honorific" or
                    select='following-sibling::*[following-sibling::*[generate-id($caption) = generate-id()]]'/>
       <xsl:if test='$content'>
        <dbk:textobject>
-         <xsl:apply-templates select='$content' mode='rnd:table-textobject'/>
+         <xsl:apply-templates select='$content' mode='rnd:textobject'/>
        </dbk:textobject>
       </xsl:if>
     </xsl:if>
   </xsl:template>
-  <xsl:template match='dbk:para' mode='rnd:table-textobject'>
+  <xsl:template match='dbk:para' mode='rnd:textobject'>
     <xsl:call-template name='rnd:para'>
       <xsl:with-param name='suppress' select='false()'/>
     </xsl:call-template>