Home     Serna Editor     Products     Downloads     Partners     About    
Syntext Serna: Rendering a Docbook Section with XSLT

NOTE: This is part of a stylesheet that Serna uses for rendering Docbook documents.


<xsl:template match="section|sect1|sect2|sect3|sect4|sect5">
  <fo:block 
    xsl:use-attribute-sets="section.block.properties">
    <xsl:call-template name="handle.empty">
      <xsl:with-param name="titles">
        <xsl:call-template name="section.titlepage"/>
      </xsl:with-param>
    </xsl:call-template>
  </fo:block>
</xsl:template>


<xsl:template name="section.titlepage">

  ... Generated template, not shown for clarity.
      Renders title, subtitle, etc.

</xsl:template>

<!-- Chooses whether to show hint when element is empty 
     or element content when it is not empty-->
<xsl:template name="handle.empty">
  <xsl:param name="titles" select="''"/>
  <xsl:variable name="toc">
    <xsl:call-template name="decorations"/>
  </xsl:variable>
  <xsl:choose>
    <xsl:when test="string-length($titles)">
      <xsl:copy-of select="$titles"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates select="." mode="empty.title.mode"/>
    </xsl:otherwise>
  </xsl:choose>
  <xsl:if test="contains($toc, 'toc')">
    <xsl:call-template name="component.toc"/>
  </xsl:if>
  <fo:block>
    <xsl:apply-templates/>
  </fo:block>
</xsl:template>

<!-- Generates element name representation when content is empty -->
<xsl:template match="section|sect1|sect2|sect3|sect4|sect5" 
              mode="empty.title.mode">
  <fo:block
    background-color="#e0e0e0"
    xsl:use-attribute-sets="title.content.properties 
                            section.title.level1.properties">
    <xsl:call-template name="gentext">
      <xsl:with-param name="key" select="concat(local-name(.), '-empty')"/>
    </xsl:call-template>
  </fo:block>
</xsl:template>