| 1 |
<?xml version='1.0'?> |
| 2 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'> |
| 3 |
|
| 4 |
<!--############################################################################ |
| 5 |
XSLT Stylesheet DocBook -> LaTeX |
| 6 |
############################################################################ --> |
| 7 |
|
| 8 |
<!-- Title parameters --> |
| 9 |
<xsl:param name="titleabbrev.in.toc">1</xsl:param> |
| 10 |
|
| 11 |
|
| 12 |
<xsl:template name="mapheading"> |
| 13 |
<xsl:call-template name="makeheading"> |
| 14 |
<xsl:with-param name="command"> |
| 15 |
<xsl:call-template name="sec-map"> |
| 16 |
<xsl:with-param name="keyword" select="local-name(.)"/> |
| 17 |
</xsl:call-template> |
| 18 |
</xsl:with-param> |
| 19 |
</xsl:call-template> |
| 20 |
</xsl:template> |
| 21 |
|
| 22 |
<xsl:template name="makeheading"> |
| 23 |
<xsl:param name="num" select="'1'"/> |
| 24 |
<xsl:param name="allnum" select="'0'"/> |
| 25 |
<xsl:param name="level"/> |
| 26 |
<xsl:param name="name"/> |
| 27 |
<xsl:param name="command"/> |
| 28 |
<!-- Title must be a node --> |
| 29 |
<xsl:param name="title" select="(title|info/title)[1]"/> |
| 30 |
|
| 31 |
<xsl:variable name="rcommand"> |
| 32 |
<xsl:choose> |
| 33 |
<xsl:when test="$command=''"> |
| 34 |
<xsl:call-template name="map.sect.level"> |
| 35 |
<xsl:with-param name="name" select="$name"/> |
| 36 |
<xsl:with-param name="level" select="$level"/> |
| 37 |
<xsl:with-param name="num" select="$num"/> |
| 38 |
<xsl:with-param name="allnum" select="$allnum"/> |
| 39 |
</xsl:call-template> |
| 40 |
</xsl:when> |
| 41 |
<xsl:otherwise> |
| 42 |
<xsl:value-of select="$command"/> |
| 43 |
</xsl:otherwise> |
| 44 |
</xsl:choose> |
| 45 |
</xsl:variable> |
| 46 |
|
| 47 |
<!-- Force section number counter if required. No consistency checked --> |
| 48 |
<xsl:if test="@label and @label!=''"> |
| 49 |
<xsl:choose> |
| 50 |
<xsl:when test="string(number(@label))='NaN' or floor(@label)!=@label"> |
| 51 |
<xsl:message> |
| 52 |
<xsl:text>Warning: only an integer in @label can be processed: '</xsl:text> |
| 53 |
<xsl:value-of select="@label"/> |
| 54 |
<xsl:text>'</xsl:text> |
| 55 |
</xsl:message> |
| 56 |
</xsl:when> |
| 57 |
<xsl:otherwise> |
| 58 |
<!-- The counter name is the same than the command --> |
| 59 |
<xsl:text>\setcounter{</xsl:text> |
| 60 |
<xsl:value-of select="substring-after($rcommand, '\')"/> |
| 61 |
<xsl:text>}{</xsl:text> |
| 62 |
<xsl:value-of select="number(@label)-1"/> |
| 63 |
<xsl:text>} </xsl:text> |
| 64 |
</xsl:otherwise> |
| 65 |
</xsl:choose> |
| 66 |
</xsl:if> |
| 67 |
|
| 68 |
<xsl:value-of select="$rcommand"/> |
| 69 |
<xsl:apply-templates select="$title" mode="format.title"> |
| 70 |
<xsl:with-param name="allnum" select="$allnum"/> |
| 71 |
</xsl:apply-templates> |
| 72 |
<xsl:call-template name="label.id"/> |
| 73 |
<xsl:apply-templates select="$title" mode="foottext"/> |
| 74 |
</xsl:template> |
| 75 |
|
| 76 |
<!-- Make a section heading from a title string. It gives something like: |
| 77 |
\section{title string}\label{label.id} |
| 78 |
--> |
| 79 |
<xsl:template name="maketitle"> |
| 80 |
<xsl:param name="num" select="'1'"/> |
| 81 |
<xsl:param name="allnum" select="'0'"/> |
| 82 |
<xsl:param name="with-label" select="1"/> |
| 83 |
<xsl:param name="level"/> |
| 84 |
<xsl:param name="name"/> |
| 85 |
<xsl:param name="command"/> |
| 86 |
<xsl:param name="title"/> |
| 87 |
|
| 88 |
<xsl:variable name="rcommand"> |
| 89 |
<xsl:choose> |
| 90 |
<xsl:when test="$command=''"> |
| 91 |
<xsl:call-template name="map.sect.level"> |
| 92 |
<xsl:with-param name="name" select="$name"/> |
| 93 |
<xsl:with-param name="level" select="$level"/> |
| 94 |
<xsl:with-param name="num" select="$num"/> |
| 95 |
<xsl:with-param name="allnum" select="$allnum"/> |
| 96 |
</xsl:call-template> |
| 97 |
</xsl:when> |
| 98 |
<xsl:otherwise> |
| 99 |
<xsl:value-of select="$command"/> |
| 100 |
</xsl:otherwise> |
| 101 |
</xsl:choose> |
| 102 |
</xsl:variable> |
| 103 |
|
| 104 |
<xsl:value-of select="$rcommand"/> |
| 105 |
<xsl:text>{</xsl:text> |
| 106 |
<xsl:value-of select="$title"/> |
| 107 |
<xsl:text>} </xsl:text> |
| 108 |
<xsl:if test="$with-label != 0"> |
| 109 |
<xsl:call-template name="label.id"/> |
| 110 |
</xsl:if> |
| 111 |
</xsl:template> |
| 112 |
|
| 113 |
|
| 114 |
<xsl:template name="label.id"> |
| 115 |
<xsl:param name="object" select="."/> |
| 116 |
<xsl:param name="string" select="''"/> |
| 117 |
<xsl:param name="inline" select="0"/> |
| 118 |
<!-- object.id cannot be used since it always provides an id --> |
| 119 |
<xsl:variable name="id"> |
| 120 |
<xsl:choose> |
| 121 |
<xsl:when test="$object/@id"> |
| 122 |
<xsl:value-of select="$object/@id"/> |
| 123 |
</xsl:when> |
| 124 |
<xsl:when test="$object/@xml:id"> |
| 125 |
<xsl:value-of select="$object/@xml:id"/> |
| 126 |
</xsl:when> |
| 127 |
</xsl:choose> |
| 128 |
</xsl:variable> |
| 129 |
|
| 130 |
<xsl:variable name="idx"> |
| 131 |
<xsl:call-template name="id-encode"> |
| 132 |
<xsl:with-param name="string" select="$id"/> |
| 133 |
</xsl:call-template> |
| 134 |
</xsl:variable> |
| 135 |
|
| 136 |
<xsl:value-of select="$string"/> |
| 137 |
<xsl:if test="$id!=''"> |
| 138 |
<xsl:text>\label{</xsl:text> |
| 139 |
<xsl:value-of select="normalize-space($idx)"/> |
| 140 |
<xsl:text>}</xsl:text> |
| 141 |
<!-- beware, hyperlabel is docbook specific --> |
| 142 |
<xsl:text>\hyperlabel{</xsl:text> |
| 143 |
<xsl:value-of select="normalize-space($idx)"/> |
| 144 |
<xsl:text>}</xsl:text> |
| 145 |
<xsl:if test="$inline=0"> |
| 146 |
<xsl:text>% </xsl:text> |
| 147 |
</xsl:if> |
| 148 |
</xsl:if> |
| 149 |
</xsl:template> |
| 150 |
|
| 151 |
<!-- Make the title part of a section heading from a title node. |
| 152 |
It gives something like: |
| 153 |
[{string in TOC}]{heading string} |
| 154 |
--> |
| 155 |
<xsl:template match="title|table/caption" mode="format.title"> |
| 156 |
<xsl:param name="allnum" select="'0'"/> |
| 157 |
<xsl:apply-templates select="." mode="toc"> |
| 158 |
<xsl:with-param name="allnum" select="$allnum"/> |
| 159 |
</xsl:apply-templates> |
| 160 |
<xsl:text>{</xsl:text> |
| 161 |
<!-- should be normalized, but it is done by post processing --> |
| 162 |
<xsl:apply-templates select="." mode="content"/> |
| 163 |
<xsl:text>} </xsl:text> |
| 164 |
</xsl:template> |
| 165 |
|
| 166 |
<!-- optionally the TOC entry text can be different from the actual |
| 167 |
title if the title contains unsupported things like hot links |
| 168 |
or graphics, or if some titleabbrev is provided and should be used |
| 169 |
for the TOC. |
| 170 |
--> |
| 171 |
<xsl:template match="title|table/caption" mode="toc"> |
| 172 |
<xsl:param name="allnum" select="0"/> |
| 173 |
<xsl:param name="pre" select="'[{'"/> |
| 174 |
<xsl:param name="post" select="'}]'"/> |
| 175 |
|
| 176 |
<!-- Use the titleabbrev for the TOC (if possible) --> |
| 177 |
<xsl:variable name="abbrev"> |
| 178 |
<xsl:if test="$titleabbrev.in.toc='1'"> |
| 179 |
<xsl:apply-templates |
| 180 |
mode="toc.skip" |
| 181 |
select="(../titleabbrev |
| 182 |
|../sect1info/titleabbrev |
| 183 |
|../sect2info/titleabbrev |
| 184 |
|../sect3info/titleabbrev |
| 185 |
|../sect4info/titleabbrev |
| 186 |
|../sect5info/titleabbrev |
| 187 |
|../sectioninfo/titleabbrev |
| 188 |
|../chapterinfo/titleabbrev |
| 189 |
|../partinfo/titleabbrev |
| 190 |
|../refsect1info/titleabbrev |
| 191 |
|../refsect2info/titleabbrev |
| 192 |
|../refsect3info/titleabbrev |
| 193 |
|../refsectioninfo/titleabbrev |
| 194 |
|../referenceinfo/titleabbrev |
| 195 |
)[1]"/> |
| 196 |
</xsl:if> |
| 197 |
</xsl:variable> |
| 198 |
|
| 199 |
<!-- Nothing in the TOC for unnumbered sections --> |
| 200 |
<xsl:variable name="unnumbered" |
| 201 |
select="parent::refsect1 |
| 202 |
|parent::refsect2 |
| 203 |
|parent::refsect3 |
| 204 |
|parent::refsection |
| 205 |
|ancestor::preface |
| 206 |
|parent::colophon |
| 207 |
|parent::dedication"/> |
| 208 |
|
| 209 |
<xsl:if test="($allnum=1 or not($unnumbered)) and |
| 210 |
($abbrev!='' or |
| 211 |
(descendant::footnote| |
| 212 |
descendant::xref| |
| 213 |
descendant::link| |
| 214 |
descendant::ulink| |
| 215 |
descendant::anchor| |
| 216 |
descendant::glossterm[@linkend]| |
| 217 |
descendant::inlinegraphic| |
| 218 |
descendant::inlinemediaobject) or |
| 219 |
(descendant::glossterm and $glossterm.auto.link != 0))"> |
| 220 |
<xsl:value-of select="$pre"/> |
| 221 |
<xsl:choose> |
| 222 |
<xsl:when test="$abbrev!=''"> |
| 223 |
<!-- The TOC contains the titleabbrev content --> |
| 224 |
<xsl:value-of select="normalize-space($abbrev)"/> |
| 225 |
</xsl:when> |
| 226 |
<xsl:otherwise> |
| 227 |
<!-- The TOC contains the toc-safe title --> |
| 228 |
<xsl:variable name="s"> |
| 229 |
<xsl:apply-templates mode="toc.skip"/> |
| 230 |
</xsl:variable> |
| 231 |
<xsl:value-of select="normalize-space($s)"/> |
| 232 |
</xsl:otherwise> |
| 233 |
</xsl:choose> |
| 234 |
<xsl:value-of select="$post"/> |
| 235 |
</xsl:if> |
| 236 |
</xsl:template> |
| 237 |
|
| 238 |
<xsl:template match="title|table/caption" mode="content"> |
| 239 |
<xsl:apply-templates/> |
| 240 |
</xsl:template> |
| 241 |
|
| 242 |
</xsl:stylesheet> |