1 <?xml version=
"1.0" encoding=
"ISO-8859-1"?> <!-- -*- sgml -*- -->
2 <!DOCTYPE xsl:stylesheet [
4 <!ENTITY line-len
"72">
6 <!-- we always output the same-length rule, so just define it as an entity -->
7 <!ENTITY rule
"------------------------------------------------------------------------">
9 <xsl:stylesheet version=
"1.0" xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform">
10 <xsl:import href=
"http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl"/>
13 <!-- line-wrapping stuff -->
14 <xsl:import href=
"line-wrap.xsl"/>
16 <!-- dump all white-space only nodes -->
17 <xsl:strip-space elements=
"*"/>
20 <xsl:output method=
"text" encoding=
"UTF-8"
21 indent=
"yes" omit-xml-declaration=
"yes"/>
23 <xsl:param name=
"generate.toc">
31 <!-- top-level place to start -->
32 <xsl:template match=
"*" mode=
"process.root">
33 <xsl:text>&nl;</xsl:text>
34 <xsl:apply-templates select=
"."/>
38 <!-- book templates -->
39 <xsl:template match=
"book">
40 <xsl:call-template name=
"book.titlepage"/>
41 <xsl:apply-templates/>
44 <xsl:template name=
"book.titlepage">
45 <xsl:text>&nl;</xsl:text>
46 <xsl:variable name=
"recto.content">
47 <xsl:apply-templates mode=
"book.titlepage.recto.auto.mode"
48 select=
"bookinfo/title"/>
49 <xsl:apply-templates mode=
"book.titlepage.recto.auto.mode"
50 select=
"bookinfo/releaseinfo"/>
51 <xsl:apply-templates mode=
"book.titlepage.recto.auto.mode"
52 select=
"bookinfo/copyright"/>
53 <xsl:apply-templates mode=
"book.titlepage.recto.auto.mode"
54 select=
"bookinfo/author"/>
56 <xsl:copy-of select=
"$recto.content"/>
60 <xsl:template match=
"title" mode=
"book.titlepage.recto.auto.mode">
61 <xsl:value-of select=
"."/>
62 <xsl:text>&nl;</xsl:text>
65 <xsl:template match=
"releaseinfo" mode=
"book.titlepage.recto.auto.mode">
66 <xsl:value-of select=
"."/>
67 <xsl:text>&nl;</xsl:text>
69 <xsl:call-template name=
"ruler">
70 <xsl:with-param name=
"char" select=
"'~'"/>
71 <xsl:with-param name=
"len" select=
"string-length(.)"/>
74 <xsl:text>&nl;</xsl:text>
78 <xsl:template match=
"copyright" mode=
"book.titlepage.recto.auto.mode"/>
80 <xsl:template match=
"author" mode=
"book.titlepage.recto.auto.mode"/>
83 <!-- article templates -->
84 <xsl:template match=
"article">
85 <xsl:call-template name=
"article.titlepage"/>
86 <xsl:apply-templates/>
90 <xsl:template name=
"article.titlepage"/>
92 <xsl:template match=
"article/title" mode=
"titlepage.mode"/>
96 <!-- qandaset / qandadiv / qandaentry templates -->
97 <xsl:template match=
"qandaset">
98 <xsl:variable name=
"title" select=
"(title)[1]"/>
99 <xsl:text>Table of Contents
</xsl:text>
100 <xsl:apply-templates select=
"$title"/>
101 <xsl:call-template name=
"process.qanda.toc"/>
102 <xsl:text>&nl;</xsl:text>
103 <!-- do the thang -->
104 <xsl:apply-templates select=
"qandaentry|qandadiv"/>
107 <xsl:template match=
"qandadiv/title">
108 <xsl:variable name=
"qalevel">
109 <xsl:call-template name=
"qandadiv.section.level"/>
112 <xsl:text>&nl;&rule;&nl;</xsl:text>
113 <xsl:apply-templates select=
"parent::qandadiv" mode=
"label.markup"/>
114 <xsl:text>.
</xsl:text>
115 <xsl:apply-templates/>
116 <xsl:text>&nl;&rule;&nl;&nl;</xsl:text>
119 <xsl:template name=
"process.qanda.toc">
120 <xsl:apply-templates select=
"qandadiv" mode=
"qandatoc.mode"/>
123 <xsl:template match=
"qandadiv" mode=
"qandatoc.mode">
124 <xsl:apply-templates select=
"title" mode=
"qandatoc.mode"/>
125 <xsl:call-template name=
"process.qanda.toc"/>
128 <xsl:template match=
"qandadiv/title" mode=
"qandatoc.mode">
129 <xsl:variable name=
"qalevel">
130 <xsl:call-template name=
"qandadiv.section.level"/>
133 <xsl:text>&nl;</xsl:text>
134 <xsl:apply-templates select=
"parent::qandadiv" mode=
"label.markup"/>
135 <xsl:text>.
</xsl:text>
137 <xsl:apply-templates/>
140 <xsl:template match=
"qandadiv">
141 <xsl:apply-templates select=
"(title)[1]"/>
142 <xsl:apply-templates select=
"qandadiv|qandaentry"/>
145 <!-- if this qandaentry is not the first child in the parent qandadiv, -->
146 <!-- then output a separator line -->
147 <xsl:template match=
"qandaentry">
148 <xsl:if test=
"position() > 1">
149 <xsl:text>&rule;&nl;&nl;</xsl:text>
151 <xsl:apply-templates/>
156 <!-- TODO: implement indenting of subsequent lines in question para -->
157 <!-- maybe pass a var 'indent' along to foldl ... ... -->
158 <xsl:template match=
"question">
159 <xsl:variable name=
"qnum">
160 <xsl:apply-templates select=
"." mode=
"label.markup"/>
163 <xsl:for-each select=
"para|screen|programlisting|itemizedlist|orderedlist">
165 <!-- glue $qnum onto the front of the first question para -->
166 <xsl:when test=
"local-name() = 'para' and position() = 1">
167 <xsl:apply-templates select=
".">
168 <xsl:with-param name=
"prefix" select=
"concat($qnum, '. ')"/>
169 </xsl:apply-templates>
172 <xsl:apply-templates select=
".">
173 <xsl:with-param name=
"prefix" select=
"zzzz"/>
174 </xsl:apply-templates>
182 <xsl:template match=
"answer">
183 <xsl:apply-templates select=
"*[name(.) != 'label']"/>
187 <xsl:template match=
"para">
188 <xsl:param name=
"prefix" select=
"''"/>
190 <!-- reformat any ulinks found -->
191 <xsl:variable name=
"text">
193 <xsl:when test=
"descendant-or-self::ulink">
194 <xsl:apply-templates name=
"ulink"/>
197 <xsl:value-of select=
"."/>
202 <!-- the input to str-split-to-lines must be delim'd by either -->
203 <!-- a space or a newline. since we need a newline at the end of -->
204 <!-- every para anyway, stick it on now -->
205 <xsl:variable name=
"pLine"
206 select=
"concat($prefix, normalize-space($text), '&nl;')"/>
209 <xsl:when test=
"string-length($pLine) < &line-len;">
210 <xsl:value-of select=
"$pLine"/>
213 <!-- TODO: this is where an 'indent' param should be sent -->
214 <xsl:call-template name=
"str-split-to-lines">
215 <xsl:with-param name=
"pStr" select=
"$pLine"/>
216 <xsl:with-param name=
"pLineLength" select=
"&line-len;"/>
217 <xsl:with-param name=
"pDelimiters" select=
"' &nl;'"/>
221 <xsl:text>&nl;</xsl:text>
225 <!-- always indent the contents of screen / programlisting -->
226 <xsl:template match=
"screen|programlisting">
227 <xsl:call-template name=
"indent.me">
228 <xsl:with-param name=
"first" select=
"'1'"/>
230 <xsl:text>&nl;</xsl:text>
234 <xsl:template match=
"itemizedlist">
235 <xsl:apply-templates select=
"listitem"/>
238 <xsl:template match=
"itemizedlist/listitem">
239 <xsl:apply-templates>
240 <xsl:with-param name=
"prefix" select=
"'* '"/>
241 </xsl:apply-templates>
245 <xsl:template match=
"orderedlist">
246 <xsl:apply-templates select=
"listitem"/>
249 <xsl:template match=
"orderedlist/listitem">
250 <xsl:apply-templates>
251 <xsl:with-param name=
"prefix" select=
"concat(position(), '. ' )"/>
252 </xsl:apply-templates>
256 <xsl:template match=
"ulink" name=
"ulink">
257 <xsl:variable name=
"url" select=
"normalize-space(@url)"/>
259 <xsl:value-of select=
"concat(text(), ': ')"/>
261 <xsl:text><</xsl:text>
263 <xsl:when test=
"starts-with($url, 'mailto:')">
264 <xsl:value-of select=
"substring-after($url, ':')"/>
267 <xsl:value-of select=
"$url"/>
270 <xsl:text>></xsl:text>
275 <!-- indent a string -->
276 <xsl:template name=
"indent.me">
277 <xsl:param name=
"text" select=
"."/>
278 <xsl:param name=
"first" select=
"'0'"/>
280 <xsl:when test=
"contains($text, '
')">
281 <xsl:value-of select=
"substring-before($text, '
')"/>
282 <xsl:if test=
"$first = 0">
283 <xsl:text>&nl;</xsl:text>
285 <xsl:text>&indent;</xsl:text>
286 <xsl:call-template name=
"indent.me">
287 <xsl:with-param name=
"text" select=
"substring-after($text, '
')"/>
291 <xsl:if test=
"not(string-length($text) = 0)">
292 <xsl:text>&indent;</xsl:text>
293 <xsl:value-of select=
"$text"/>
294 <xsl:text>&nl;</xsl:text>
301 <!-- Repeat the character 'char' 'len' times -->
302 <xsl:template name=
"ruler">
303 <xsl:param name=
"char"/>
304 <xsl:param name=
"len"/>
305 <xsl:param name=
"line"/>
307 <xsl:when test=
"$len = 0">
308 <xsl:value-of select=
"$line"/>
309 <xsl:text>&nl;</xsl:text>
311 <xsl:when test=
"$len mod 2 = 1">
312 <xsl:call-template name=
"ruler">
313 <xsl:with-param name=
"char" select=
"concat($char,$char)"/>
314 <xsl:with-param name=
"len" select=
"($len - 1) div 2"/>
315 <xsl:with-param name=
"line" select=
"concat($line,$char)"/>
319 <xsl:call-template name=
"ruler">
320 <xsl:with-param name=
"char" select=
"concat($char,$char)"/>
321 <xsl:with-param name=
"len" select=
"$len div 2"/>
322 <xsl:with-param name=
"line" select=
"$line"/>