Search code examples
xsltdocbook

Docbook <bibliosource> gets lost in the transformation


I have the following structure

    <informalfigure xmlns="http://docbook.org/ns/docbook">
      <info>
        <bibliosource>Photo: John Doe</bibliosource>
      </info>
      <mediaobject>
        <imageobject>
          <imagedata contentdepth="30mm" contentwidth="35mm" fileref="path/to/img.jpg"/>
        </imageobject>
      </mediaobject>
      <caption>
        <para>Here goes the caption for the image</para>
      </caption>
    </informalfigure>

<imagedata> and the <caption> get rendered but the <bibliosource> is gone after the transformation.

I'm using the docbook-xsl-1.77.0/xhtml/docbook.xsl for the transformation... I need some guidance on where/how to change the xslt so that <bibliosource> gets transformed properly.

Thanks!


Solution

  • Here is a simple solution. Add the following to your XHTML customization layer:

    <xsl:template match="d:caption">
      <div>
        <xsl:apply-templates select="." mode="common.html.attributes"/>
        <xsl:call-template name="id.attribute"/>
        <xsl:if test="@align = 'right' or @align = 'left' or @align='center'">
          <xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute>
        </xsl:if>
        <xsl:apply-templates/>
       </div>
       <div><xsl:value-of select="../d:info/d:bibliosource"/></div>   <!-- This line added -->
    </xsl:template>
    

    The above works with the namespace-aware XSLT stylesheets (docbook-xsl-ns).

    If you use the non-namespace-aware stylesheets (docbook-xsl), the corresponding customization becomes:

    <xsl:template match="caption">
      <div>
        <xsl:apply-templates select="." mode="common.html.attributes"/>
        <xsl:call-template name="id.attribute"/>
        <xsl:if test="@align = 'right' or @align = 'left' or @align='center'">
          <xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute>
        </xsl:if>
        <xsl:apply-templates/>
       </div>
       <div><xsl:value-of select="../blockinfo/bibliosource"/></div>   <!-- This line added; note blockinfo -->
    </xsl:template>
    

    The text of the <bibliosource> element will appear in a separate <div> directly below the caption. The original template is in graphics.xsl.