<chapter>
<title>Extensions</title>
<?dbhtml filename="extensions.html"?>

  <para>The DocBook XSL Stylesheets distribution includes a set of
    DocBook-specific XSLT extensions (currently implemented in Java)
    for performing a variety of functions that would be impractical to
    implement with standard XSLT only:
    <itemizedlist>
      <listitem>
        <para>embed callouts in verbatim environments (program
          listings, for example)</para>
      </listitem>
      <listitem>
        <para>add line numbers to verbatim environments (program
          listings, for example)</para>
      </listitem>
      <listitem>
        <para>adjust the width of table columns in HTML output to
          match specs in the CALS table source</para>
      </listitem>
      <listitem>
        <para>directly include contents of a text file in rendered
          output</para>
      </listitem>
      <listitem>
        <para>determine the intrinsic size of an image</para>
      </listitem>
    </itemizedlist>
  </para>

  <para>The line numbers and callouts in the following example are
  made possible through the use of the DocBook XSLT extension
  functions.
    <example>
    <title>A program listing with line numbering and callouts</title>
<programlistingco>
<areaspec>
<area coords="1" id="prologue"/>
<area coords="4" id="skipeof"/>
<areaset coords="" id="xreq">
<area coords="9" id="require1"/>
<area coords="10" id="require2"/>
</areaset>
<area coords="11 12" id="use"/>
<area coords="27" id="funccall"/>
</areaspec>
<programlisting linenumbering='numbered'>@rem = '--*-Perl-*--
@echo off
perl.exe %_batchname %$
goto endofperl
@rem ';

# Compress mail...

require 'n:/home/nwalsh/lib/cygnus.pl';
require 'timelocal.pl';
use Cwd;

select (STDERR); $| = 1;
select (STDOUT); $| = 1;

@DIRS = ("/home/nwalsh/Mail");
while (@DIRS) {
    $dir = shift @DIRS;
    opendir (DIR, $dir);
    while ($fname = readdir(DIR)) {
        $file = "$dir/$fname";
        next if ! -d $file;
        next if $fname =~ /^\.\.?$/;

        print "$file\n";
        push (@DIRS, $file);
        &amp;compress ($file);
    }
}

exit;</programlisting>
<calloutlist>
<callout arearefs="prologue">
<para>The prologue handles embedding a Perl script in a DOS batch file.</para>
</callout>
<callout arearefs="skipeof">
<para>The <literal>goto</literal> statement, interpreted by the DOS batch
file interpreter, skips over the body of the Perl script.</para>
</callout>
<callout arearefs="require1">
<para>The <literal>require</literal> statement sources in external program
fragments.</para>
</callout>
<callout arearefs="use">
<para>The <literal>use</literal> statement is similar, but has additional
utility.  It is a Perl5 function.  (Note that this callout area specifies
both a line and a column.)</para>
</callout>
<callout arearefs="funccall">
<para>This is a user subroutine call.</para>
</callout>
</calloutlist>
</programlistingco>
</example>
</para>

<section>
<title>Using the Extensions</title>

      <para>The extensions are included in the DocBook XSL Stylesheets
      distribution in the <filename
        class="directory">extensions</filename> directory.
      </para>
      <procedure>
      <para>To use the extensions, you need to:</para>
      <step>
          <para>Determine which extension jar file (in the <filename
            class="directory">extensions</filename> directory) corresponds most
          closely to the Java XSLT engine you use.</para>
        </step>
        <step>
          <para>Include the name of that jar file in your Java
          <envar>CLASSPATH</envar>.</para>
        </step>
        <step>
        <para>Set the correct <ulink url="html/" >XSLT extension
            parameters</ulink> to enable the behavior you need. (For
          compatibility with other processors, the extensions are
          disabled by default.)</para>
        </step>
      </procedure>

    <para>
      For example, if you're using Saxon 6.4.4, include the
      <filename>extensions/saxon644.jar</filename> file in your Java
      classpath. If you're using Xalan-Java 2, include the
      <filename>extensions/xalan2.jar</filename> file in your
      classpath.

      <note>
        <para>The DocBook XSLT extensions are not supported for
          Xalan-Java 1 or for versions of Saxon prior to 6.4.3. And
          because the only current implementation of the extensions is
          written in Java, you can't yet use them with xsltproc (which
          is a written in C) or with Xalan-C++.
        </para>
      </note>

      At a minimum, you'll also need to set the value of the <ulink
        url="html/use.extensions.html" >use.extensions</ulink>
      parameter to <literal>1</literal> (instead of the default
      <literal>0</literal>).</para>
    <example>
      <title>Enabling the extensions from the command line</title>
      <para>To enable the extensions from the command line, you need to
        pass the <parameter>use.extensions</parameter> parameter
      to your XSLT engine. Here's an example of how to do that with Saxon:
        <screen format="linespecific">
  java com.icl.saxon.StyleSheet  <replaceable>filename.xml</replaceable> <replaceable>docbook/html/docbook.xsl \
</replaceable>    use.extensions=1 &gt; <replaceable>output.html</replaceable>
</screen>
      and here's an example of how to do it with Xalan:
        <screen format="linespecific">
  java org.apache.xalan.xslt.Process -IN <replaceable>filename.xml</replaceable> -XSL <replaceable>docbook/html/docbook.xsl</replaceable> \
    -PARAM use.extensions 1 -OUT <replaceable>output.html</replaceable>  
</screen>
      </para>
    </example>
  </section>

</chapter>

