File: //usr/share/doc/docbook-style-xsl-1.69.1/doc/ch05.html
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Chapter 5. The Template System</title><link rel="stylesheet" href="reference.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.69.0"><link rel="start" href="index.html" title="DocBook XSL Stylesheet Documentation"><link rel="up" href="index.html" title="DocBook XSL Stylesheet Documentation"><link rel="prev" href="ch04.html" title="Chapter 4. Reference Documentation"><link rel="next" href="htmlhelp.html" title="Chapter 6. Using the XSL stylesheets to generate HTML Help"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 5. The Template System</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch04.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="htmlhelp.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="d0e911"></a>Chapter 5. The Template System</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Norman</span> <span class="surname">Walsh</span></h3></div></div><div><p class="releaseinfo">
$Id: templates.xml,v 1.2 2005/03/07 22:15:03 bobstayton Exp $
</p></div><div><p class="copyright">Copyright © 2000 Norman Walsh</p></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="ch05.html#d0e935">Changing the Article Title Page</a></span></dt></dl></div><p>Some parts of the DocBook XSL Stylesheets are actually generated
using XSL Stylesheets. In particular, the formatting of title pages
is generated using a special template system. The same template system
will eventually allow you to easily customize bibliography entries and
perhaps other parts of the system as well.</p><p>FIXME: there needs to be more introductory/explanatory text
here!</p><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e935"></a>Changing the Article Title Page</h2></div></div></div><p>In order to demonstrate how this system works, let's consider
how we can use it to change the format of article title pages.</p><p>By default, the stylesheets print the following elements on the
article title page, in this order: <span class="simplelist"><code class="sgmltag-element">title</code>, <code class="sgmltag-element">subtitle</code>, <code class="sgmltag-element">corpauthor</code>, <code class="sgmltag-element">authorgroup</code>, <code class="sgmltag-element">author</code>, <code class="sgmltag-element">releaseinfo</code>, <code class="sgmltag-element">copyright</code>, <code class="sgmltag-element">legalnotice</code>, <code class="sgmltag-element">pubdate</code>, <code class="sgmltag-element">revision</code>, <code class="sgmltag-element">revhistory</code>, <code class="sgmltag-element">abstract</code></span>. Suppose we want to put only the
<code class="sgmltag-element">title</code>, <code class="sgmltag-element">author</code>, and
<code class="sgmltag-element">edition</code> elements on the title page, in the order
that they appear in the <code class="sgmltag-element">articleinfo</code>.
</p><p>The “<span class="quote">hard</span>” (and wrong!) way to do it would be to
edit <code class="filename">titlepage.templates.xsl</code> and make the changes
by hand.</p><p>The easy and right way is to construct a template document that
describes the order and sequence of elements that you want:</p><pre class="screen">
<t:templates xmlns:t="http://nwalsh.com/docbook/xsl/template/1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
base-stylesheet="/path/to/html/docbook.xsl">
<t:titlepage element="article" wrapper="div" class="titlepage">
<t:titlepage-content side="recto" order="document">
<title predicate="[1]"/>
<author/>
<edition/>
</t:titlepage-content>
</t:titlepage>
</t:templates>
</pre><p>Then process this document with the
<code class="filename">template/titlepage.xsl</code> stylesheet. This will
produce the following somewhat cryptic stylesheet:</p><pre class="screen">
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- This stylesheet was created by titlepage.xsl; do not edit it by hand. -->
<xsl:template name="article.titlepage.recto"><xsl:apply-templates mode="article.titlepage.recto.mode" select="(articleinfo/title|artheader/title|title)[1]|articleinfo/author|artheader/author|articleinfo/edition|artheader/edition"/>
</xsl:template>
<xsl:template name="article.titlepage">
<div class="titlepage">
<xsl:call-template name="article.titlepage.before.recto"/>
<xsl:call-template name="article.titlepage.recto"/>
<xsl:call-template name="article.titlepage.before.verso"/>
<xsl:call-template name="article.titlepage.verso"/>
<xsl:call-template name="article.titlepage.separator"/>
</div>
</xsl:template>
</xsl:stylesheet>
</pre><p>Despite its cryptic appearance, it has the desired result.
When you use <code class="literal">xsl:include</code> to include these
generated templates into the main stylesheet, then they are
used to format the title page elements.
The elements are selected and processed in the order you specified.
</p><p>
If you want to change <span class="emphasis"><em>how</em></span> the titlepage elements
are formatted (as opposed to which ones are formatted), you have to
write your own customization layer that overrides the template for
the element in question in the “<span class="quote">titlepage.mode</span>” mode.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch04.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="htmlhelp.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 4. Reference Documentation </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 6. Using the XSL stylesheets to generate HTML Help</td></tr></table></div></body></html>