<?xml version="1.0" encoding="utf-8"?>
<!-- This file was generated by weave.xsl version 0.00+. Do not edit! -->
<!-- See http://sourceforge.net/projects/docbook/ -->
<!DOCTYPE article
  PUBLIC "-//DocBook Open Repository//DTD DocBook Literate Programming V0.0//EN" "http://docbook.sourceforge.net/release/litprog/current/dtd/ldocbook.dtd">
<article xmlns:src="http://nwalsh.com/xmlns/litprog/fragment" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<articleinfo>
<title>Literate DocBook XML Stylesheets</title>
<subtitle>Part of
<citetitle>Literate Programming in XML</citetitle></subtitle>
<pubdate>05 Oct 2001</pubdate>
<releaseinfo role="meta">
$Id: ldocbook.xweb,v 1.4 2002/01/06 19:27:56 nwalsh Exp $
</releaseinfo>

<revhistory>
<revision>
<revnumber>0.1</revnumber>
<date>05 Oct 2001</date>
<authorinitials>ndw</authorinitials>
<revremark>Initial draft.</revremark>
</revision>
</revhistory>

<author><firstname>Norman</firstname><surname>Walsh</surname>
</author>
</articleinfo>

<!-- ============================================================ -->

<para>The <filename>ldocbook.xsl</filename> stylesheet transforms an
<acronym>XWEB</acronym> documentation file (a <quote>woven</quote> <acronym>XWEB</acronym> document)
into HTML documentation.</para>

<para>This stylesheet assumes that fragments appear inside DocBook
<sgmltag>section</sgmltag> elements. Some additional customization of
the <src:fragref linkend="fragment-label"/> and
<src:fragref linkend="fragment-title"/> will be required
to support a different organization.</para>

<section><title>The Stylesheets</title>

<para>This document describes both the HTML and XSL Formatting Objects
versions of the stylesheet.</para>

<section><title>The HTML Stylesheet</title>

<para>The stylesheet performs some initialization and establishes
templates for the Literate Programming elements that can appear in
the documentation. Most of the documentation elements will be
DocBook elements handled by the imported stylesheet.</para>

<src:fragment id="top">&lt;xsl:stylesheet xmlns:fo="http://www.w3.org/1999/XSL/Format"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:verb="com.nwalsh.saxon.Verbatim"
                exclude-result-prefixes="verb src"
                version="1.0"&gt;
  &lt;xsl:import xmlns:fo="http://www.w3.org/1999/XSL/Format"
              xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:verb="com.nwalsh.saxon.Verbatim"
              href="http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl"/&gt;

  <src:fragref linkend="init"/>
  <src:fragref linkend="proc-html-fragment"/>
  <src:fragref linkend="proc-html-fragref"/>
&lt;/xsl:stylesheet&gt;</src:fragment>

</section>

<section><title>The Chunking HTML Stylesheet</title>

<para>The stylesheet performs some initialization and establishes
templates for the Literate Programming elements that can appear in
the documentation. Most of the documentation elements will be
DocBook elements handled by the imported stylesheet.</para>

<src:fragment id="top-chunk">&lt;xsl:stylesheet xmlns:fo="http://www.w3.org/1999/XSL/Format"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:verb="com.nwalsh.saxon.Verbatim"
                exclude-result-prefixes="verb src"
                version="1.0"&gt;
  &lt;xsl:import xmlns:fo="http://www.w3.org/1999/XSL/Format"
              xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:verb="com.nwalsh.saxon.Verbatim"
              href="http://docbook.sourceforge.net/release/xsl/current/html/chunk.xsl"/&gt;

  <src:fragref linkend="init"/>
  <src:fragref linkend="proc-html-fragment"/>
  <src:fragref linkend="proc-html-fragref"/>
&lt;/xsl:stylesheet&gt;</src:fragment>

</section>

<section><title>The FO Stylesheet</title>

<para>The stylesheet performs some initialization and establishes
templates for the Literate Programming elements that can appear in
the documentation. Most of the documentation elements will be
DocBook elements handled by the imported stylesheet.</para>

<src:fragment id="fo-top">&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:verb="com.nwalsh.saxon.Verbatim"
                exclude-result-prefixes="verb src fo"
                version="1.0"&gt;

  &lt;xsl:import xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
              xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:verb="com.nwalsh.saxon.Verbatim"
              href="http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl"/&gt;

  &lt;xsl:param xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
             xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:verb="com.nwalsh.saxon.Verbatim"
             name="page.margin.outer"
             select="'1in'"/&gt;
  &lt;xsl:param xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
             xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:verb="com.nwalsh.saxon.Verbatim"
             name="title.margin.left"
             select="'-0pt'"/&gt;

  <src:fragref linkend="init"/>
  <src:fragref linkend="proc-fo-fragment"/>
  <src:fragref linkend="proc-fo-fragref"/>
&lt;/xsl:stylesheet&gt;</src:fragment>
</section>

<section><title>Initialization</title>

<para>The stylesheet initializes the processor by loading its version
information (stored in a separate file because it is shared by several
stylesheets), importing the base DocBook stylesheet, setting some
parameters, and setting up
some internationalized text.</para>

<src:fragment id="init">  &lt;xsl:include href="../VERSION"/&gt;

  &lt;xsl:template match="revhistory"
                mode="titlepage.mode"/&gt;

  <src:fragref linkend="param"/>
  <src:fragref linkend="i18n"/></src:fragment>

<section><title>Parameters</title>

<para>In DocBook Literate Programming documentation, we always number
sections and verbatim environments.</para>

<src:fragment id="param">&lt;xsl:param name="section.autolabel"
           select="1"/&gt;
&lt;xsl:param name="linenumbering.everyNth"
           select="5"/&gt;
&lt;xsl:param name="linenumbering.separator"
           select="'| '"/&gt;</src:fragment>
</section>

<section><title>Localization</title>

<para>Localized text in the DocBook stylesheets makes use of an
external document to determine the nature of, among other things,
element titles and cross references.</para>

<para>Cross references to <sgmltag>src:fragments</sgmltag> are not
supported in the stock stylesheets (since there is no such element
in DocBook).</para>

<para>In order to make cross references work properly, we must provide
an appropriate localization for <sgmltag>src:fragment</sgmltag> titles.
We do this by pointing the <parameter>local.l10n.xml</parameter>
<emphasis>at ourselves</emphasis> (at the stylesheet document).</para>

<para>In our local localization document, we add an
<sgmltag>l:i18n</sgmltag> element to provide the necessary context.</para>

<para>If you want to support DocBook Literate Programming in other
languages, this section will have to be updated.</para>

<src:fragment id="i18n">&lt;xsl:param name="local.l10n.xml"
           select="document('')"/&gt;

&lt;l:i18n&gt;
  &lt;l:l10n language="en"&gt;
   &lt;l:context name="title"&gt;
      &lt;l:template name="fragment"
                  text="%t"/&gt;
    &lt;/l:context&gt;
  &lt;/l:l10n&gt;
&lt;/l:i18n&gt;</src:fragment>
</section>
</section>
</section>

<section><title>Process HTML Fragments</title>

<para>Fragments are output as verbatim environments with numbered lines,
if possible. A table is used to make the listings stand out.</para>

<src:fragment id="proc-html-fragment">&lt;xsl:template match="src:fragment"&gt;
  &lt;xsl:param name="suppress-numbers"
             select="'0'"/&gt;
  &lt;xsl:param name="linenumbering"
             select="'numbered'"/&gt;

  &lt;xsl:variable name="section"
                select="ancestor::section[1]"/&gt;
  &lt;xsl:variable name="id"
                select="@id"/&gt;
  &lt;xsl:variable name="referents"
                select="//src:fragment[.//src:fragref[@linkend=$id]]"/&gt;

  &lt;div class="src-fragment"&gt;
  &lt;a name="{@id}"/&gt;
  &lt;table border="1"
         width="100%"&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;p&gt;
          &lt;b&gt;
            &lt;xsl:apply-templates select="."
                                 mode="label.markup"/&gt;
          &lt;/b&gt;
          &lt;xsl:if test="$referents"&gt;
            &lt;xsl:text&gt;: &lt;/xsl:text&gt;
            &lt;xsl:for-each select="$referents"&gt;
              &lt;xsl:if test="position() &gt; 1"&gt;, &lt;/xsl:if&gt;
              &lt;a&gt;
                &lt;xsl:attribute name="href"&gt;
                  &lt;xsl:call-template name="href.target"&gt;
                    &lt;xsl:with-param name="object"
                                    select="."/&gt;
                  &lt;/xsl:call-template&gt;
                &lt;/xsl:attribute&gt;
                &lt;xsl:apply-templates select="."
                                     mode="label.markup"/&gt;
              &lt;/a&gt;
            &lt;/xsl:for-each&gt;
          &lt;/xsl:if&gt;
        &lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;xsl:choose&gt;
          &lt;xsl:when test="$suppress-numbers = '0'                           and $linenumbering = 'numbered'                           and $use.extensions != '0'                           and $linenumbering.extension != '0'"&gt;
            &lt;xsl:variable name="rtf"&gt;
              &lt;xsl:apply-templates/&gt;
            &lt;/xsl:variable&gt;
            &lt;pre class="{name(.)}"&gt;
              &lt;xsl:copy-of select="verb:numberLines($rtf)"/&gt;
            &lt;/pre&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;
            &lt;pre class="{name(.)}"&gt;
              &lt;xsl:apply-templates/&gt;
            &lt;/pre&gt;
          &lt;/xsl:otherwise&gt;
        &lt;/xsl:choose&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/div&gt;
&lt;/xsl:template&gt;

<src:fragref linkend="fragment-label"/>
<src:fragref linkend="fragment-title"/></src:fragment>

<para>Fragment labels and titles must also be supported.</para>

<section><title>Fragment Labels</title>

<para>A fragment label consists of a section mark followed by the
label of the current section and the number of the fragment within
that section.</para>

<src:fragment id="fragment-label">&lt;xsl:template match="src:fragment"
              mode="label.markup"&gt;
  &lt;xsl:variable name="section"
                select="ancestor::section[1]"/&gt;

  &lt;xsl:text&gt;§&lt;/xsl:text&gt;

  &lt;xsl:choose&gt;
    &lt;xsl:when test="$section"&gt;
      &lt;xsl:variable name="section.label"&gt;
        &lt;xsl:apply-templates select="$section"
                             mode="label.markup"/&gt;
      &lt;/xsl:variable&gt;
      &lt;xsl:choose&gt;
        &lt;xsl:when test="string($section.label) = ''"&gt;
          &lt;xsl:number from="section"/&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:otherwise&gt;
          &lt;xsl:copy-of select="$section.label"/&gt;
          &lt;xsl:text&gt;.&lt;/xsl:text&gt;
          &lt;xsl:number from="section"/&gt;
        &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:otherwise&gt;
      &lt;xsl:number from="/"/&gt;
    &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
&lt;/xsl:template&gt;</src:fragment>
</section>

<section><title>Fragment Titles</title>

<para>A fragment title is the title of the section that contains it.
</para>

<src:fragment id="fragment-title">&lt;xsl:template match="src:fragment"
              mode="title.markup"&gt;
  &lt;xsl:variable name="section"
                select="ancestor::section[1]"/&gt;

  &lt;xsl:if test="$section"&gt;
    &lt;xsl:apply-templates select="$section"
                         mode="title.markup"/&gt;
  &lt;/xsl:if&gt;
&lt;/xsl:template&gt;</src:fragment>
</section>
</section>

<section><title>Process FO Fragments</title>

<para>Fragments are output as verbatim environments with numbered lines,
if possible.</para>

<src:fragment id="proc-fo-fragment">&lt;xsl:template match="src:fragment"&gt;
  &lt;xsl:param name="suppress-numbers"
             select="'0'"/&gt;
  &lt;xsl:param name="linenumbering"
             select="'numbered'"/&gt;

  &lt;xsl:variable name="section"
                select="ancestor::section[1]"/&gt;
  &lt;xsl:variable name="id"
                select="@id"/&gt;
  &lt;xsl:variable name="referents"
                select="//src:fragment[.//src:fragref[@linkend=$id]]"/&gt;

  &lt;fo:block xsl:use-attribute-sets="formal.object.properties"
            keep-together="always"
            border-style="solid"
            border-width="0pt"
            border-before-width="0.25pt"
            border-after-width="0.25pt"&gt;
    &lt;fo:block id="{@id}"
              border-width="0pt"
              border-style="solid"
              border-after-width="0.25pt"&gt;
      &lt;fo:inline font-weight="bold"&gt;
        &lt;xsl:apply-templates select="."
                             mode="label.markup"/&gt;
      &lt;/fo:inline&gt;
      &lt;fo:inline&gt;
        &lt;xsl:if test="$referents"&gt;
          &lt;xsl:text&gt;: &lt;/xsl:text&gt;
          &lt;xsl:for-each select="$referents"&gt;
            &lt;xsl:if test="position() &gt; 1"&gt;, &lt;/xsl:if&gt;
            &lt;xsl:apply-templates select="."
                                 mode="label.markup"/&gt;
          &lt;/xsl:for-each&gt;
        &lt;/xsl:if&gt;
      &lt;/fo:inline&gt;
    &lt;/fo:block&gt;

    &lt;fo:block wrap-option="no-wrap"
              text-align="start"
              white-space-collapse="false"
              linefeed-treatment="preserve"
              xsl:use-attribute-sets="monospace.verbatim.properties"&gt;
      &lt;xsl:variable name="rtf"&gt;
        &lt;xsl:apply-templates/&gt;
      &lt;/xsl:variable&gt;

      &lt;xsl:choose&gt;
        &lt;xsl:when test="$suppress-numbers = '0'                         and $linenumbering = 'numbered'                         and $use.extensions != '0'                         and $linenumbering.extension != '0'"&gt;
          &lt;xsl:call-template name="number.rtf.lines"&gt;
            &lt;xsl:with-param name="rtf"
                            select="$rtf"/&gt;
          &lt;/xsl:call-template&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:otherwise&gt;
          &lt;xsl:copy-of select="$rtf"/&gt;
        &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
    &lt;/fo:block&gt;
  &lt;/fo:block&gt;
&lt;/xsl:template&gt;

<src:fragref linkend="fragment-label"/>
<src:fragref linkend="fragment-title"/></src:fragment>
</section>

<section><title>Process HTML Fragment References</title>

<para>A fragment reference has exactly the same semantics as a DocBook
<sgmltag>xref</sgmltag>.</para>

<src:fragment id="proc-html-fragref">&lt;xsl:template match="src:fragref"&gt;
  &lt;xsl:call-template name="xref"/&gt;
&lt;/xsl:template&gt;
<src:fragref linkend="fragref-html-xref-to"/></src:fragment>

<section><title>Fragment Cross-Reference Text</title>

<para>Cross references to fragments produce the fragment label
and title.</para>

<src:fragment id="fragref-html-xref-to">&lt;xsl:template match="src:fragment"
              mode="xref-to"&gt;
  &lt;xsl:variable name="section"
                select="ancestor::section[1]"/&gt;

  &lt;i&gt;
    &lt;xsl:apply-templates select="."
                         mode="label.markup"/&gt;
    &lt;xsl:text&gt;. &lt;/xsl:text&gt;
    &lt;xsl:apply-templates select="."
                         mode="title.markup"/&gt;
  &lt;/i&gt;
&lt;/xsl:template&gt;</src:fragment>
</section>
</section>

<section><title>Process FO Fragment References</title>

<para>A fragment reference has exactly the same semantics as a DocBook
<sgmltag>xref</sgmltag>.</para>

<src:fragment id="proc-fo-fragref">&lt;xsl:template match="src:fragref"&gt;
  &lt;xsl:call-template name="xref"/&gt;
&lt;/xsl:template&gt;
<src:fragref linkend="fragref-fo-xref-to"/></src:fragment>

<section><title>Fragment Cross-Reference Text</title>

<para>Cross references to fragments produce the fragment label
and title.</para>

<src:fragment id="fragref-fo-xref-to">&lt;xsl:template match="src:fragment"
              mode="xref-to"&gt;
  &lt;xsl:variable name="section"
                select="ancestor::section[1]"/&gt;

  &lt;fo:inline font-style="italic"&gt;
    &lt;xsl:apply-templates select="."
                         mode="label.markup"/&gt;
    &lt;xsl:text&gt;. &lt;/xsl:text&gt;
    &lt;xsl:apply-templates select="."
                         mode="title.markup"/&gt;
  &lt;/fo:inline&gt;
&lt;/xsl:template&gt;</src:fragment>
</section>
</section>

</article>