Next / Previous / Contents / NM Tech homepage

7.6. HTML block element customizations

At this point there is only one customized block element, programlisting.

7.6.1. The programlisting element

When using the literate programming features of the local DocBook toolchain, we look for programlisting elements that have a role attribute that start with "outFile:". In that case:

  1. We output the file name from the role attribute, in small type, right-justified, to identify the file to which the following block is written.

  2. To format the literate block, we call the template from Section 7.6.2, “The html-lit-block template: Formatting a literate block”.

Here is the template that handles HTML programlisting elements. If it is a literate code block, that is, if the role attribute is present and its initial characters are "outFile:", we save the rest of the attribute value in the variable fileName.

zdp_html.xsl
  <!--programlisting: Process code; implement literate features-->
  <xsl:template match="d:programlisting">
    <xsl:choose>
      <xsl:when test="@role and starts-with(@role, 'outFile:')">
        <xsl:variable name='fileName' select="substring(@role,9)"/>

The div element used to right-align the output file name is formatted using the Section 10.4.4, “div.code-block-label. Then we call Section 7.6.2, “The html-lit-block template: Formatting a literate block”.

zdp_html.xsl
        <!--Literate block: Show the destination file name and use
         !  a different CSS class
         !-->
        <div class="code-block-label">
          <xsl:value-of select="$fileName"/>
        </div>
        <xsl:call-template name="html-lit-block"/>
      </xsl:when>

If it is not a literate block, the apply-imports operation punts the formatting to the default programlisting template.

zdp_html.xsl
      <xsl:otherwise>
        <xsl:apply-imports/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>