| 1 |
<html><head> |
| 2 |
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| 3 |
<title>Chapter 4. The Template System</title><link rel="stylesheet" href="reference.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.37"><link rel="home" href="index.html" title="DocBook XSL Stylesheet Documentation"><link rel="up" href="index.html" title="DocBook XSL Stylesheet Documentation"><link rel="previous" href="ch03.html" title="Chapter 3. Reference Documentation"></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 4. The Template System</th></tr><tr><td width="20%" align="left"><a href="ch03.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> </td></tr></table><hr></div><p>Some parts of the DocBook XSL Stylesheets are actually generated |
| 4 |
using XSL Stylesheets. In particular, the formatting of title pages |
| 5 |
is generated using a special template system. The same template system |
| 6 |
will eventually allow you to easily customize bibliography entries and |
| 7 |
perhaps other parts of the system as well.</p><p>FIXME: there needs to be more introductory/explanatory text |
| 8 |
here!</p><p>In order to demonstrate how this system works, let's consider |
| 9 |
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 |
| 10 |
article title page, in this order: <span class="simplelist"><tt>title</tt>, <tt>subtitle</tt>, <tt>corpauthor</tt>, <tt>authorgroup</tt>, <tt>author</tt>, <tt>releaseinfo</tt>, <tt>copyright</tt>, <tt>legalnotice</tt>, <tt>pubdate</tt>, <tt>revision</tt>, <tt>revhistory</tt>, <tt>abstract</tt></span>. Suppose we want to put only the |
| 11 |
<tt>title</tt>, <tt>author</tt>, and |
| 12 |
<tt>edition</tt> elements on the title page, in the order |
| 13 |
that they appear in the <tt>articleinfo</tt>. |
| 14 |
</p><p>The “hard” (and wrong!) way to do it would be to |
| 15 |
edit <tt>titlepage.templates.xsl</tt> and make the changes |
| 16 |
by hand.</p><p>The easy and right way is to construct a template document that |
| 17 |
describes the order and sequence of elements that you want:</p><pre class="screen"> |
| 18 |
<t:templates xmlns:t="http://nwalsh.com/docbook/xsl/template/1.0" |
| 19 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 20 |
base-stylesheet="/path/to/html/docbook.xsl"> |
| 21 |
|
| 22 |
<t:titlepage element="article" wrapper="div" class="titlepage"> |
| 23 |
<t:titlepage-content side="recto" order="document"> |
| 24 |
<title predicate="[1]"/> |
| 25 |
<author/> |
| 26 |
<edition/> |
| 27 |
</t:titlepage-content> |
| 28 |
</t:titlepage> |
| 29 |
</t:templates> |
| 30 |
</pre><p>Then process this document with the |
| 31 |
<tt>template/titlepage.xsl</tt> stylesheet. This will |
| 32 |
produce the following somewhat cryptic stylesheet:</p><pre class="screen"> |
| 33 |
<?xml version="1.0" encoding="utf-8"?> |
| 34 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> |
| 35 |
|
| 36 |
<!-- This stylesheet was created by titlepage.xsl; do not edit it by hand. --> |
| 37 |
|
| 38 |
<xsl:import href="/path/to/html/docbook.xsl"/> |
| 39 |
|
| 40 |
<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"/> |
| 41 |
</xsl:template> |
| 42 |
|
| 43 |
<xsl:template name="article.titlepage"> |
| 44 |
<div class="titlepage"> |
| 45 |
<xsl:call-template name="article.titlepage.before.recto"/> |
| 46 |
<xsl:call-template name="article.titlepage.recto"/> |
| 47 |
<xsl:call-template name="article.titlepage.before.verso"/> |
| 48 |
<xsl:call-template name="article.titlepage.verso"/> |
| 49 |
<xsl:call-template name="article.titlepage.separator"/> |
| 50 |
</div> |
| 51 |
</xsl:template> |
| 52 |
|
| 53 |
</xsl:stylesheet> |
| 54 |
</pre><p>Despite its cryptic appearance, it has the desired result. |
| 55 |
If you want to change <i>how</i> the titlepage elements |
| 56 |
are formatted (as opposed to which ones are formatted), you have to |
| 57 |
write your own customization layer that overrides the template for |
| 58 |
the element in question in the “titlepage.mode” mode.</p><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a href="ch03.html">Prev</a> </td><td width="20%" align="center"><a href="index.html">Home</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left">Chapter 3. Reference Documentation </td><td width="20%" align="center"><a href="index.html">Up</a></td><td width="40%" align="right"> </td></tr></table></div></body></html> |