docbook_xsl_wrapper 0.1.2 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/CHANGELOG +41 -0
  4. data/README.md +9 -17
  5. data/bin/docbook_xsl_wrapper +9 -14
  6. data/docbook_xsl_wrapper.gemspec +8 -7
  7. data/lib/docbook_xsl_wrapper.rb +24 -1
  8. data/lib/docbook_xsl_wrapper/epub.rb +124 -122
  9. data/lib/docbook_xsl_wrapper/options.rb +1 -1
  10. data/lib/docbook_xsl_wrapper/validate.rb +22 -0
  11. data/lib/docbook_xsl_wrapper/version.rb +1 -1
  12. data/schema/docbookxi.rng +18654 -0
  13. data/spec/docbook_xsl_wrapper/validate_spec.rb +64 -0
  14. data/xsl/AUTHORS +4 -0
  15. data/xsl/COPYING +48 -0
  16. data/xsl/REVISION +1 -0
  17. data/xsl/VERSION.xsl +115 -0
  18. data/xsl/common/addns.xsl +124 -0
  19. data/xsl/common/af.xml +1272 -0
  20. data/xsl/common/am.xml +1272 -0
  21. data/xsl/common/ar.xml +1272 -0
  22. data/xsl/common/as.xml +703 -0
  23. data/xsl/common/ast.xml +703 -0
  24. data/xsl/common/autoidx-kimber.xsl +45 -0
  25. data/xsl/common/autoidx-kosek.xsl +155 -0
  26. data/xsl/common/az.xml +715 -0
  27. data/xsl/common/bg.xml +767 -0
  28. data/xsl/common/bn.xml +1272 -0
  29. data/xsl/common/bn_in.xml +703 -0
  30. data/xsl/common/bs.xml +705 -0
  31. data/xsl/common/ca.xml +703 -0
  32. data/xsl/common/charmap.xsl +222 -0
  33. data/xsl/common/common.xsl +2129 -0
  34. data/xsl/common/cs.xml +743 -0
  35. data/xsl/common/cy.xml +1288 -0
  36. data/xsl/common/da.xml +707 -0
  37. data/xsl/common/de.xml +709 -0
  38. data/xsl/common/el.xml +772 -0
  39. data/xsl/common/en.xml +1272 -0
  40. data/xsl/common/entities.ent +67 -0
  41. data/xsl/common/eo.xml +1272 -0
  42. data/xsl/common/es.xml +719 -0
  43. data/xsl/common/et.xml +1272 -0
  44. data/xsl/common/eu.xml +1272 -0
  45. data/xsl/common/fa.xml +703 -0
  46. data/xsl/common/fi.xml +713 -0
  47. data/xsl/common/fr.xml +733 -0
  48. data/xsl/common/ga.xml +1272 -0
  49. data/xsl/common/gentext.xsl +855 -0
  50. data/xsl/common/gl.xml +1272 -0
  51. data/xsl/common/gu.xml +703 -0
  52. data/xsl/common/he.xml +1272 -0
  53. data/xsl/common/hi.xml +703 -0
  54. data/xsl/common/hr.xml +705 -0
  55. data/xsl/common/hu.xml +721 -0
  56. data/xsl/common/id.xml +1272 -0
  57. data/xsl/common/insertfile.xsl +113 -0
  58. data/xsl/common/is.xml +715 -0
  59. data/xsl/common/it.xml +1272 -0
  60. data/xsl/common/ja.xml +703 -0
  61. data/xsl/common/ka.xml +743 -0
  62. data/xsl/common/kn.xml +1272 -0
  63. data/xsl/common/ko.xml +1272 -0
  64. data/xsl/common/ky.xml +775 -0
  65. data/xsl/common/l10n.dtd +64 -0
  66. data/xsl/common/l10n.xml +78 -0
  67. data/xsl/common/l10n.xsl +598 -0
  68. data/xsl/common/la.xml +1272 -0
  69. data/xsl/common/labels.xsl +933 -0
  70. data/xsl/common/lt.xml +721 -0
  71. data/xsl/common/lv.xml +1272 -0
  72. data/xsl/common/ml.xml +703 -0
  73. data/xsl/common/mn.xml +773 -0
  74. data/xsl/common/mr.xml +703 -0
  75. data/xsl/common/nb.xml +1272 -0
  76. data/xsl/common/nds.xml +709 -0
  77. data/xsl/common/nl.xml +703 -0
  78. data/xsl/common/nn.xml +1272 -0
  79. data/xsl/common/olink.xsl +1284 -0
  80. data/xsl/common/or.xml +1272 -0
  81. data/xsl/common/pa.xml +703 -0
  82. data/xsl/common/pi.xml +168 -0
  83. data/xsl/common/pi.xsl +347 -0
  84. data/xsl/common/pl.xml +721 -0
  85. data/xsl/common/pt.xml +1272 -0
  86. data/xsl/common/pt_br.xml +1272 -0
  87. data/xsl/common/refentry.xsl +1353 -0
  88. data/xsl/common/ro.xml +1272 -0
  89. data/xsl/common/ru.xml +769 -0
  90. data/xsl/common/sk.xml +1272 -0
  91. data/xsl/common/sl.xml +1272 -0
  92. data/xsl/common/sq.xml +1272 -0
  93. data/xsl/common/sr.xml +763 -0
  94. data/xsl/common/sr_Latn.xml +722 -0
  95. data/xsl/common/subtitles.xsl +181 -0
  96. data/xsl/common/sv.xml +707 -0
  97. data/xsl/common/ta.xml +703 -0
  98. data/xsl/common/table.xsl +515 -0
  99. data/xsl/common/targetdatabase.dtd +49 -0
  100. data/xsl/common/targets.xsl +338 -0
  101. data/xsl/common/te.xml +703 -0
  102. data/xsl/common/th.xml +1272 -0
  103. data/xsl/common/titles.xsl +850 -0
  104. data/xsl/common/tl.xml +1272 -0
  105. data/xsl/common/tr.xml +709 -0
  106. data/xsl/common/uk.xml +769 -0
  107. data/xsl/common/ur.xml +705 -0
  108. data/xsl/common/utility.xsl +291 -0
  109. data/xsl/common/vi.xml +1272 -0
  110. data/xsl/common/xh.xml +1272 -0
  111. data/xsl/common/zh.xml +703 -0
  112. data/xsl/common/zh_cn.xml +703 -0
  113. data/xsl/common/zh_tw.xml +703 -0
  114. data/xsl/epub/docbook.xsl +1769 -0
  115. data/xsl/epub3/chunk.xsl +30 -0
  116. data/xsl/epub3/docbook-epub.css.xml +142 -0
  117. data/xsl/epub3/docbook.xsl +20 -0
  118. data/xsl/epub3/epub3-chunk-mods.xsl +52 -0
  119. data/xsl/epub3/epub3-element-mods.xsl +2533 -0
  120. data/xsl/epub3/titlepage.templates.xml +712 -0
  121. data/xsl/epub3/titlepage.templates.xsl +3842 -0
  122. data/xsl/lib/lib.xsl +533 -0
  123. data/xsl/xhtml/admon.xsl +142 -0
  124. data/xsl/xhtml/annotations.xsl +160 -0
  125. data/xsl/xhtml/autoidx.xsl +831 -0
  126. data/xsl/xhtml/autotoc.xsl +706 -0
  127. data/xsl/xhtml/biblio-iso690.xsl +1302 -0
  128. data/xsl/xhtml/biblio.xsl +1371 -0
  129. data/xsl/xhtml/block.xsl +584 -0
  130. data/xsl/xhtml/callout.xsl +210 -0
  131. data/xsl/xhtml/chunk-code.xsl +675 -0
  132. data/xsl/xhtml/chunk-common.xsl +1627 -0
  133. data/xsl/xhtml/chunker.xsl +317 -0
  134. data/xsl/xhtml/component.xsl +440 -0
  135. data/xsl/xhtml/division.xsl +214 -0
  136. data/xsl/xhtml/ebnf.xsl +331 -0
  137. data/xsl/xhtml/footnote.xsl +346 -0
  138. data/xsl/xhtml/formal.xsl +496 -0
  139. data/xsl/xhtml/glossary.xsl +602 -0
  140. data/xsl/xhtml/graphics.xsl +1537 -0
  141. data/xsl/xhtml/html-rtf.xsl +321 -0
  142. data/xsl/xhtml/html.xsl +690 -0
  143. data/xsl/xhtml/htmltbl.xsl +102 -0
  144. data/xsl/xhtml/index.xsl +264 -0
  145. data/xsl/xhtml/info.xsl +48 -0
  146. data/xsl/xhtml/inline.xsl +1508 -0
  147. data/xsl/xhtml/its.xsl +109 -0
  148. data/xsl/xhtml/keywords.xsl +38 -0
  149. data/xsl/xhtml/lists.xsl +1227 -0
  150. data/xsl/xhtml/math.xsl +286 -0
  151. data/xsl/xhtml/param.xsl +449 -0
  152. data/xsl/xhtml/pi.xsl +1237 -0
  153. data/xsl/xhtml/qandaset.xsl +440 -0
  154. data/xsl/xhtml/refentry.xsl +307 -0
  155. data/xsl/xhtml/sections.xsl +564 -0
  156. data/xsl/xhtml/synop.xsl +1623 -0
  157. data/xsl/xhtml/table.xsl +1179 -0
  158. data/xsl/xhtml/task.xsl +76 -0
  159. data/xsl/xhtml/titlepage.templates.xsl +4005 -0
  160. data/xsl/xhtml/titlepage.xsl +1108 -0
  161. data/xsl/xhtml/toc.xsl +334 -0
  162. data/xsl/xhtml/verbatim.xsl +389 -0
  163. data/xsl/xhtml/xref.xsl +1268 -0
  164. data/xsl/xhtml5/docbook.xsl +22 -0
  165. data/xsl/xhtml5/html5-chunk-mods.xsl +112 -0
  166. data/xsl/xhtml5/html5-element-mods.xsl +791 -0
  167. data/xsl/xhtml5/xhtml-docbook.xsl +531 -0
  168. metadata +207 -27
  169. data/.rvmrc +0 -48
  170. data/xslt/obfuscate.xsl +0 -12
@@ -0,0 +1,1769 @@
1
+ <?xml version="1.0"?>
2
+ <xsl:stylesheet
3
+ xmlns:db="http://docbook.org/ns/docbook"
4
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
5
+ xmlns:exsl="http://exslt.org/common"
6
+ xmlns:h="http://www.w3.org/1999/xhtml"
7
+ xmlns:ncx="http://www.daisy.org/z3986/2005/ncx/"
8
+ xmlns:ng="http://docbook.org/docbook-ng"
9
+ xmlns:opf="http://www.idpf.org/2007/opf"
10
+ xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
11
+ xmlns:str="http://exslt.org/strings"
12
+ xmlns:date="http://exslt.org/dates-and-times"
13
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
14
+ xmlns:d="http://docbook.org/ns/docbook"
15
+ xmlns:xtext="xalan://com.nwalsh.xalan.Text"
16
+
17
+ extension-element-prefixes="date stext xtext"
18
+ exclude-result-prefixes="exsl date db dc h ncx ng opf stext str xtext d"
19
+
20
+ version="1.0">
21
+
22
+ <xsl:import href="../xhtml-1_1/docbook.xsl" />
23
+ <xsl:import href="../xhtml-1_1/chunk-common.xsl" />
24
+ <xsl:include href="../xhtml-1_1/chunk-code.xsl" />
25
+
26
+
27
+ <!-- We want a separate TOC file, please -->
28
+ <xsl:param name="chunk.tocs.and.lots">1</xsl:param>
29
+ <xsl:param name="toc.section.depth">2</xsl:param>
30
+ <xsl:param name="generate.toc">
31
+ book toc,title
32
+ </xsl:param>
33
+
34
+ <xsl:param name="ade.extensions" select="0"/>
35
+ <xsl:param name="epub.autolabel" select="'1'"/>
36
+ <xsl:param name="epub.ncx.depth">4</xsl:param> <!-- Not functional until http://code.google.com/p/epubcheck/issues/detail?id=70 is resolved -->
37
+
38
+ <xsl:param name="manifest.in.base.dir" select="'1'"/>
39
+ <xsl:param name="base.dir" select="''"/>
40
+ <xsl:param name="epub.oebps.dir" select="'OEBPS/'"/>
41
+
42
+ <!-- HTML chunk output goes to $base.dir/OEPBS -->
43
+ <xsl:variable name="chunk.base.dir">
44
+ <xsl:if test="$base.dir != '' and contains($base.dir, $epub.oebps.dir)">
45
+ <xsl:message terminate="yes">
46
+ <xsl:text>ERROR: the $base.dir param must not include the </xsl:text>
47
+ <xsl:value-of select="$epub.oebps.dir"/>
48
+ <xsl:text> directory in its path. Exiting.</xsl:text>
49
+ </xsl:message>
50
+ </xsl:if>
51
+ <xsl:choose>
52
+ <xsl:when test="string-length($base.dir) = 0"></xsl:when>
53
+ <!-- make sure to add trailing slash if omitted by user -->
54
+ <xsl:when test="substring($base.dir, string-length($base.dir), 1) = '/'">
55
+ <xsl:value-of select="$base.dir"/>
56
+ </xsl:when>
57
+ <xsl:otherwise>
58
+ <xsl:value-of select="concat($base.dir, '/')"/>
59
+ </xsl:otherwise>
60
+ </xsl:choose>
61
+ <xsl:value-of select="$epub.oebps.dir"/>
62
+ <xsl:if test="substring($epub.oebps.dir, string-length($epub.oebps.dir), 1) != '/'">
63
+ <xsl:text>/</xsl:text>
64
+ </xsl:if>
65
+ </xsl:variable>
66
+
67
+ <!-- This param only has a side effect of checking for base.dir usage -->
68
+
69
+ <xsl:param name="epub.ncx.filename" select="'toc.ncx'"/>
70
+ <xsl:param name="epub.container.filename" select="'container.xml'"/>
71
+ <xsl:param name="epub.opf.filename" select="concat($epub.oebps.dir, 'content.opf')"/>
72
+ <xsl:param name="epub.cover.filename" select="concat($chunk.base.dir, 'cover', $html.ext)"/>
73
+ <xsl:param name="epub.cover.id" select="'cover'"/>
74
+ <xsl:param name="epub.cover.html" select="'cover.html'" />
75
+ <xsl:param name="epub.cover.image.id" select="'cover-image'"/>
76
+ <xsl:param name="epub.cover.linear" select="0" />
77
+ <xsl:param name="epub.ncx.toc.id">ncxtoc</xsl:param>
78
+ <xsl:param name="epub.html.toc.id">htmltoc</xsl:param>
79
+ <xsl:variable name="epub.metainf.dir" select="concat($base.dir, 'META-INF/')"/>
80
+
81
+ <xsl:param name="epub.embedded.fonts"></xsl:param>
82
+
83
+ <!-- Turning this on crashes ADE, which is unbelievably awesome -->
84
+ <xsl:param name="formal.object.break.after">0</xsl:param>
85
+
86
+
87
+ <!-- Per Bob Stayton:
88
+ """Process your documents with the css.decoration parameter set to zero.
89
+ That will avoid the use of style attributes in XHTML elements where they are not permitted."""
90
+ http://www.sagehill.net/docbookxsl/OtherOutputForms.html#StrictXhtmlValid -->
91
+ <xsl:param name="css.decoration" select="0"/>
92
+ <xsl:param name="custom.css.source"></xsl:param> <!-- FIXME: Align with current CSS parameter design -->
93
+
94
+ <xsl:param name="callout.graphics" select="1"/>
95
+ <xsl:param name="callout.graphics.extension">.png</xsl:param>
96
+ <xsl:param name="callout.graphics.number.limit" select="15"/>
97
+ <xsl:param name="callout.graphics.path" select="'images/callouts/'"/>
98
+
99
+ <!-- no navigation in .epub -->
100
+ <xsl:param name="suppress.navigation" select="'1'"/>
101
+
102
+ <xsl:variable name="toc.params">
103
+ <xsl:call-template name="find.path.params">
104
+ <xsl:with-param name="node" select="/*"/>
105
+ <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
106
+ </xsl:call-template>
107
+ </xsl:variable>
108
+ <xsl:variable name="root.is.a.chunk">
109
+ <xsl:choose>
110
+ <xsl:when test="/*[not(self::d:book)][not(d:sect1) or not(d:section)]">
111
+ <xsl:text>1</xsl:text>
112
+ </xsl:when>
113
+ <xsl:when test="/d:book[*[last()][self::d:bookinfo]]|d:book[d:bookinfo]">
114
+ <xsl:text>1</xsl:text>
115
+ </xsl:when>
116
+ <xsl:when test="/d:book[*[last()][self::d:info]]|d:book[d:info]">
117
+ <xsl:text>1</xsl:text>
118
+ </xsl:when>
119
+ <xsl:when test="/d:bibliography">
120
+ <xsl:text>1</xsl:text>
121
+ </xsl:when>
122
+ <xsl:otherwise>
123
+ <xsl:text>0</xsl:text>
124
+ </xsl:otherwise>
125
+ </xsl:choose>
126
+ </xsl:variable>
127
+
128
+ <xsl:key name="image-filerefs" match="d:graphic|d:inlinegraphic|d:imagedata" use="@fileref"/>
129
+
130
+ <xsl:template match="/" priority="1">
131
+ <!-- * Get a title for current doc so that we let the user -->
132
+ <!-- * know what document we are processing at this point. -->
133
+ <xsl:variable name="doc.title">
134
+ <xsl:call-template name="get.doc.title" />
135
+ </xsl:variable>
136
+ <xsl:choose>
137
+ <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
138
+ toss the namespace and continue. Use the docbook5 namespaced
139
+ stylesheets for DocBook5 if you don't want to use this feature.-->
140
+ <!-- include extra test for Xalan quirk -->
141
+ <xsl:when test="$exsl.node.set.available != 0
142
+ and (*/self::ng:* or */self::db:*)">
143
+ <xsl:call-template name="log.message">
144
+ <xsl:with-param name="level">Note</xsl:with-param>
145
+ <xsl:with-param name="source" select="$doc.title" />
146
+ <xsl:with-param name="context-desc">
147
+ <xsl:text>namesp. add</xsl:text>
148
+ </xsl:with-param>
149
+ <xsl:with-param name="message">
150
+ <xsl:text>added namespace before processing</xsl:text>
151
+ </xsl:with-param>
152
+ </xsl:call-template>
153
+ <xsl:variable name="nons">
154
+ <xsl:apply-templates mode="addNS" />
155
+ </xsl:variable>
156
+ <xsl:call-template name="log.message">
157
+ <xsl:with-param name="level">Note</xsl:with-param>
158
+ <xsl:with-param name="source" select="$doc.title" />
159
+ <xsl:with-param name="context-desc">
160
+ <xsl:text>namesp. add</xsl:text>
161
+ </xsl:with-param>
162
+ <xsl:with-param name="message">
163
+ <xsl:text>processing stripped document</xsl:text>
164
+ </xsl:with-param>
165
+ </xsl:call-template>
166
+ <xsl:apply-templates select="exsl:node-set($nons)" />
167
+ </xsl:when>
168
+ <xsl:otherwise>
169
+ <xsl:choose>
170
+ <xsl:when test="$rootid != ''">
171
+ <xsl:choose>
172
+ <xsl:when
173
+ test="count(key('id',$rootid)) = 0">
174
+ <xsl:message terminate="yes">
175
+ <xsl:text>ID '</xsl:text>
176
+ <xsl:value-of select="$rootid" />
177
+ <xsl:text>' not found in document.</xsl:text>
178
+ </xsl:message>
179
+ </xsl:when>
180
+ <xsl:otherwise>
181
+ <xsl:if
182
+ test="$collect.xref.targets = 'yes' or
183
+ $collect.xref.targets = 'only'">
184
+ <xsl:apply-templates
185
+ select="key('id', $rootid)" mode="collect.targets" />
186
+ </xsl:if>
187
+ <xsl:if
188
+ test="$collect.xref.targets != 'only'">
189
+ <xsl:message>
190
+ Formatting from
191
+ <xsl:value-of select="$rootid" />
192
+ </xsl:message>
193
+ <xsl:apply-templates
194
+ select="key('id',$rootid)" mode="process.root" />
195
+ <xsl:call-template name="ncx" />
196
+ </xsl:if>
197
+ </xsl:otherwise>
198
+ </xsl:choose>
199
+ </xsl:when>
200
+ <xsl:otherwise>
201
+ <xsl:if
202
+ test="$collect.xref.targets = 'yes' or
203
+ $collect.xref.targets = 'only'">
204
+ <xsl:apply-templates select="/"
205
+ mode="collect.targets" />
206
+ </xsl:if>
207
+ <xsl:if
208
+ test="$collect.xref.targets != 'only'">
209
+ <xsl:apply-templates select="/"
210
+ mode="process.root" />
211
+ <xsl:call-template name="ncx" />
212
+ <xsl:call-template name="opf" />
213
+ <xsl:call-template name="cover" />
214
+ <xsl:call-template name="container" />
215
+ </xsl:if>
216
+ </xsl:otherwise>
217
+ </xsl:choose>
218
+ </xsl:otherwise>
219
+ </xsl:choose>
220
+ </xsl:template>
221
+
222
+ <xsl:template name="package-identifier">
223
+ <xsl:variable name="info" select="*/*[contains(local-name(.), 'info')][1]"/>
224
+
225
+ <xsl:choose>
226
+ <xsl:when test="$info/d:biblioid">
227
+ <xsl:if test="$info/d:biblioid[1][@class = 'doi' or
228
+ @class = 'isbn' or
229
+ @class = 'isrn' or
230
+ @class = 'issn']">
231
+ <xsl:text>urn:</xsl:text>
232
+ <xsl:value-of select="$info/d:biblioid[1]/@class"/>
233
+ <xsl:text>:</xsl:text>
234
+ </xsl:if>
235
+ <xsl:value-of select="$info/d:biblioid[1]"/>
236
+ </xsl:when>
237
+ <xsl:when test="$info/d:isbn">
238
+ <xsl:text>urn:isbn:</xsl:text>
239
+ <xsl:value-of select="$info/d:isbn[1]"/>
240
+ </xsl:when>
241
+ <xsl:when test="$info/d:issn">
242
+ <xsl:text>urn:issn:</xsl:text>
243
+ <xsl:value-of select="$info/d:issn[1]"/>
244
+ </xsl:when>
245
+ <xsl:otherwise>
246
+ <xsl:choose>
247
+ <xsl:when test="$info/d:invpartnumber">
248
+ <xsl:value-of select="$info/d:invpartnumber[1]"/>
249
+ </xsl:when>
250
+ <xsl:when test="$info/d:issuenum">
251
+ <xsl:value-of select="$info[1]/d:issuenum[1]"/>
252
+ </xsl:when>
253
+ <xsl:when test="$info/d:productnumber">
254
+ <xsl:value-of select="$info[1]/d:productnumber[1]"/>
255
+ </xsl:when>
256
+ <xsl:when test="$info/d:seriesvolnums">
257
+ <xsl:value-of select="$info[1]/d:seriesvolnums[1]"/>
258
+ </xsl:when>
259
+ <xsl:when test="$info/d:volumenum">
260
+ <xsl:value-of select="$info[1]/d:volumenum[1]"/>
261
+ </xsl:when>
262
+ <!-- Deprecated -->
263
+ <xsl:when test="$info/d:pubsnumber">
264
+ <xsl:value-of select="$info[1]/d:pubsnumber[1]"/>
265
+ </xsl:when>
266
+ </xsl:choose>
267
+ <xsl:text>_</xsl:text>
268
+ <xsl:choose>
269
+ <xsl:when test="@id">
270
+ <xsl:value-of select="@id"/>
271
+ </xsl:when>
272
+ <xsl:when test="@xml:id">
273
+ <xsl:value-of select="@xml:id"/>
274
+ </xsl:when>
275
+ <xsl:otherwise>
276
+ <!-- TODO: Do UUIDs here -->
277
+ <xsl:value-of select="generate-id(.)"/>
278
+ </xsl:otherwise>
279
+ </xsl:choose>
280
+ </xsl:otherwise>
281
+ </xsl:choose>
282
+ </xsl:template>
283
+
284
+
285
+ <xsl:template name="opf">
286
+ <xsl:variable name="package-identifier-id"><xsl:value-of select="concat(name(/*), 'id')"/></xsl:variable>
287
+ <xsl:variable name="doc.title">
288
+ <xsl:call-template name="get.doc.title" />
289
+ </xsl:variable>
290
+ <xsl:call-template name="write.chunk">
291
+ <xsl:with-param name="filename">
292
+ <xsl:value-of select="concat($base.dir, $epub.opf.filename)" />
293
+ </xsl:with-param>
294
+ <xsl:with-param name="method" select="'xml'" />
295
+ <xsl:with-param name="encoding" select="'utf-8'" />
296
+ <xsl:with-param name="indent" select="'no'" />
297
+ <xsl:with-param name="quiet" select="$chunk.quietly" />
298
+ <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
299
+ <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
300
+ <xsl:with-param name="content">
301
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="package">
302
+ <xsl:attribute name="version">2.0</xsl:attribute>
303
+ <xsl:attribute name="unique-identifier"> <xsl:value-of select="$package-identifier-id"/> </xsl:attribute>
304
+
305
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="metadata">
306
+ <xsl:element name="dc:identifier">
307
+ <xsl:attribute name="id"><xsl:value-of select="$package-identifier-id"/></xsl:attribute>
308
+ <xsl:call-template name="package-identifier"/>
309
+ </xsl:element>
310
+
311
+ <xsl:element name="dc:title">
312
+ <xsl:value-of select="normalize-space($doc.title)"/>
313
+ </xsl:element>
314
+
315
+ <xsl:apply-templates select="/*/*[contains(name(.), 'info')]/*"
316
+ mode="opf.metadata"/>
317
+ <xsl:element name="dc:language">
318
+ <xsl:call-template name="l10n.language">
319
+ <xsl:with-param name="target" select="/*"/>
320
+ </xsl:call-template>
321
+ </xsl:element>
322
+
323
+ <xsl:if test="/*/*[d:cover or contains(name(.), 'info')]//d:mediaobject[@role='cover' or ancestor::d:cover]">
324
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="meta">
325
+ <xsl:attribute name="name">cover</xsl:attribute>
326
+ <xsl:attribute name="content">
327
+ <xsl:value-of select="$epub.cover.image.id"/>
328
+ </xsl:attribute>
329
+ </xsl:element>
330
+ </xsl:if>
331
+
332
+ </xsl:element>
333
+ <xsl:call-template name="opf.manifest"/>
334
+ <xsl:call-template name="opf.spine"/>
335
+ <xsl:call-template name="opf.guide"/>
336
+
337
+ </xsl:element>
338
+ </xsl:with-param>
339
+ </xsl:call-template>
340
+ </xsl:template>
341
+
342
+ <xsl:template name="container">
343
+ <xsl:call-template name="write.chunk">
344
+ <xsl:with-param name="filename">
345
+ <xsl:value-of select="concat($epub.metainf.dir, $epub.container.filename)" />
346
+ </xsl:with-param>
347
+ <xsl:with-param name="method" select="'xml'" />
348
+ <xsl:with-param name="encoding" select="'utf-8'" />
349
+ <xsl:with-param name="indent" select="'no'" />
350
+ <xsl:with-param name="quiet" select="$chunk.quietly" />
351
+ <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
352
+ <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
353
+
354
+ <xsl:with-param name="content">
355
+ <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="container">
356
+ <xsl:attribute name="version">1.0</xsl:attribute>
357
+ <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="rootfiles">
358
+ <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="rootfile">
359
+ <xsl:attribute name="full-path">
360
+ <xsl:value-of select="$epub.opf.filename" />
361
+ </xsl:attribute>
362
+ <xsl:attribute name="media-type">
363
+ <xsl:text>application/oebps-package+xml</xsl:text>
364
+ </xsl:attribute>
365
+ </xsl:element>
366
+ </xsl:element>
367
+ </xsl:element>
368
+ </xsl:with-param>
369
+ </xsl:call-template>
370
+ </xsl:template>
371
+
372
+ <xsl:template name="ncx">
373
+ <xsl:call-template name="write.chunk">
374
+ <xsl:with-param name="filename">
375
+ <xsl:if test="$manifest.in.base.dir != 0">
376
+ <xsl:value-of select="$chunk.base.dir" />
377
+ </xsl:if>
378
+ <xsl:value-of select="$epub.ncx.filename" />
379
+ </xsl:with-param>
380
+ <xsl:with-param name="method" select="'xml'" />
381
+ <xsl:with-param name="encoding" select="'utf-8'" />
382
+ <xsl:with-param name="indent" select="'no'" />
383
+ <xsl:with-param name="quiet" select="$chunk.quietly" />
384
+ <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
385
+ <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
386
+ <xsl:with-param name="content">
387
+ <xsl:element name="ncx" namespace="http://www.daisy.org/z3986/2005/ncx/">
388
+ <xsl:attribute name="version">2005-1</xsl:attribute>
389
+
390
+ <!-- Via Martin Goerner: On covers: the IDPF2.0 standard unfortunately does not have a provision for
391
+ covers. We had to add one and we did so in conjunction with the IDPF and
392
+ various publishers. The tag chosen to define the covers is:
393
+ <meta name="cover" content="-reference to a manifest item-">
394
+ Then, we also added a bit of logic to get rid cleanly of the HTML cover
395
+ people usually add because the logical cover is not specced by the IDPF. So,
396
+ if the HTML cover item is marked linear="no" AND there is a guide item of
397
+ type="cover" pointing to it AND there is a logical cover specified in a
398
+ <meta name="cover"> tag, THEN, the HTML cover is discarded. -->
399
+ <xsl:element name="head" namespace="http://www.daisy.org/z3986/2005/ncx/">
400
+ <xsl:if test="/*/*[d:cover or contains(name(.), 'info')]//d:mediaobject[@role='cover' or ancestor::d:cover]">
401
+ <xsl:element name="meta" namespace="http://www.daisy.org/z3986/2005/ncx/">
402
+ <xsl:attribute name="name">cover</xsl:attribute>
403
+ <xsl:attribute name="content">
404
+ <xsl:value-of select="$epub.cover.id"/>
405
+ </xsl:attribute>
406
+ </xsl:element>
407
+ </xsl:if>
408
+ <xsl:element name="meta" namespace="http://www.daisy.org/z3986/2005/ncx/">
409
+ <xsl:attribute name="name">dtb:uid</xsl:attribute>
410
+ <xsl:attribute name="content"><xsl:call-template name="package-identifier"/></xsl:attribute>
411
+ </xsl:element>
412
+ </xsl:element>
413
+
414
+ <xsl:choose>
415
+ <xsl:when test="$rootid != ''">
416
+ <xsl:variable name="title">
417
+ <xsl:if test="$epub.autolabel != 0">
418
+ <xsl:variable name="label.markup">
419
+ <xsl:apply-templates select="key('id',$rootid)" mode="label.markup" />
420
+ </xsl:variable>
421
+ <xsl:if test="normalize-space($label.markup)">
422
+ <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
423
+ </xsl:if>
424
+ </xsl:if>
425
+ <xsl:apply-templates select="key('id',$rootid)" mode="title.markup" />
426
+ </xsl:variable>
427
+ <xsl:variable name="href">
428
+ <xsl:call-template name="href.target.with.base.dir">
429
+ <xsl:with-param name="object" select="key('id',$rootid)" />
430
+ </xsl:call-template>
431
+ </xsl:variable>
432
+ <xsl:element name="docTitle" namespace="http://www.daisy.org/z3986/2005/ncx/">
433
+ <xsl:element name="text" namespace="http://www.daisy.org/z3986/2005/ncx/"><xsl:value-of select="normalize-space($title)" /> </xsl:element>
434
+ </xsl:element>
435
+ <xsl:element name="navMap" namespace="http://www.daisy.org/z3986/2005/ncx/">
436
+ <xsl:apply-templates select="key('id',$rootid)/*" mode="ncx" />
437
+ </xsl:element>
438
+ </xsl:when>
439
+ <xsl:otherwise>
440
+ <xsl:variable name="title">
441
+ <xsl:if test="$epub.autolabel != 0">
442
+ <xsl:variable name="label.markup">
443
+ <xsl:apply-templates select="/*" mode="label.markup" />
444
+ </xsl:variable>
445
+ <xsl:if test="normalize-space($label.markup)">
446
+ <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
447
+ </xsl:if>
448
+ </xsl:if>
449
+ <xsl:apply-templates select="/*" mode="title.markup" />
450
+ </xsl:variable>
451
+ <xsl:variable name="href">
452
+ <xsl:call-template name="href.target.with.base.dir">
453
+ <xsl:with-param name="object" select="/" />
454
+ </xsl:call-template>
455
+ </xsl:variable>
456
+ <xsl:element name="docTitle" namespace="http://www.daisy.org/z3986/2005/ncx/">
457
+ <xsl:element name="text" namespace="http://www.daisy.org/z3986/2005/ncx/">
458
+ <xsl:value-of select="normalize-space($title)" />
459
+ </xsl:element>
460
+ </xsl:element>
461
+ <xsl:element name="navMap" namespace="http://www.daisy.org/z3986/2005/ncx/">
462
+ <xsl:choose>
463
+ <xsl:when test="$root.is.a.chunk != '0'">
464
+ <xsl:apply-templates select="/*" mode="ncx" />
465
+ </xsl:when>
466
+ <xsl:otherwise>
467
+ <xsl:apply-templates select="/*/*" mode="ncx" />
468
+ </xsl:otherwise>
469
+ </xsl:choose>
470
+ </xsl:element>
471
+ </xsl:otherwise>
472
+
473
+ </xsl:choose>
474
+ </xsl:element>
475
+ </xsl:with-param>
476
+ </xsl:call-template>
477
+ </xsl:template>
478
+
479
+ <xsl:template match="d:book|
480
+ d:article|
481
+ d:part|
482
+ d:reference|
483
+ d:preface|
484
+ d:chapter|
485
+ d:bibliography|
486
+ d:appendix|
487
+ d:glossary|
488
+ d:section|
489
+ d:sect1|
490
+ d:sect2|
491
+ d:sect3|
492
+ d:sect4|
493
+ d:sect5|
494
+ d:refentry|
495
+ d:colophon|
496
+ d:bibliodiv[d:title]|
497
+ d:setindex|
498
+ d:index"
499
+ mode="ncx">
500
+ <xsl:variable name="depth" select="count(ancestor::*)"/>
501
+ <xsl:variable name="title">
502
+ <xsl:if test="$epub.autolabel != 0">
503
+ <xsl:variable name="label.markup">
504
+ <xsl:apply-templates select="." mode="label.markup" />
505
+ </xsl:variable>
506
+ <xsl:if test="normalize-space($label.markup)">
507
+ <xsl:value-of
508
+ select="concat($label.markup,$autotoc.label.separator)" />
509
+ </xsl:if>
510
+ </xsl:if>
511
+ <xsl:apply-templates select="." mode="title.markup" />
512
+ </xsl:variable>
513
+
514
+ <xsl:variable name="href">
515
+ <xsl:call-template name="href.target.with.base.dir">
516
+ <xsl:with-param name="context" select="/" />
517
+ <!-- Generate links relative to the location of root file/toc.xml file -->
518
+ </xsl:call-template>
519
+ </xsl:variable>
520
+
521
+ <xsl:variable name="id">
522
+ <xsl:value-of select="generate-id(.)"/>
523
+ </xsl:variable>
524
+ <xsl:variable name="order">
525
+ <xsl:value-of select="$depth +
526
+ count(preceding::d:part|
527
+ preceding::d:reference|
528
+ preceding::d:book[parent::d:set]|
529
+ preceding::d:preface|
530
+ preceding::d:chapter|
531
+ preceding::d:bibliography|
532
+ preceding::d:appendix|
533
+ preceding::d:article|
534
+ preceding::d:glossary|
535
+ preceding::d:section[not(parent::d:partintro)]|
536
+ preceding::d:sect1[not(parent::d:partintro)]|
537
+ preceding::d:sect2[not(ancestor::d:partintro)]|
538
+ preceding::d:sect3[not(ancestor::d:partintro)]|
539
+ preceding::d:sect4[not(ancestor::d:partintro)]|
540
+ preceding::d:sect5[not(ancestor::d:partintro)]|
541
+ preceding::d:refentry|
542
+ preceding::d:colophon|
543
+ preceding::d:bibliodiv[d:title]|
544
+ preceding::d:index)"/>
545
+ </xsl:variable>
546
+
547
+ <xsl:element name="navPoint" namespace="http://www.daisy.org/z3986/2005/ncx/">
548
+ <xsl:attribute name="id">
549
+ <xsl:value-of select="$id"/>
550
+ </xsl:attribute>
551
+
552
+ <xsl:attribute name="playOrder">
553
+ <xsl:choose>
554
+ <xsl:when test="/*[self::d:set]">
555
+ <xsl:value-of select="$order"/>
556
+ </xsl:when>
557
+ <xsl:when test="$root.is.a.chunk != '0'">
558
+ <xsl:value-of select="$order + 1"/>
559
+ </xsl:when>
560
+ <xsl:otherwise>
561
+ <xsl:value-of select="$order - 0"/>
562
+ </xsl:otherwise>
563
+ </xsl:choose>
564
+ </xsl:attribute>
565
+ <xsl:element name="navLabel" namespace="http://www.daisy.org/z3986/2005/ncx/">
566
+ <xsl:element name="text" namespace="http://www.daisy.org/z3986/2005/ncx/"><xsl:value-of select="normalize-space($title)"/> </xsl:element>
567
+ </xsl:element>
568
+ <xsl:element name="content" namespace="http://www.daisy.org/z3986/2005/ncx/">
569
+ <xsl:attribute name="src">
570
+ <xsl:value-of select="$href"/>
571
+ </xsl:attribute>
572
+ </xsl:element>
573
+ <xsl:apply-templates select="d:book[parent::d:set]|d:part|d:reference|d:preface|d:chapter|d:bibliography|d:appendix|d:article|d:glossary|d:section|d:sect1|d:sect2|d:sect3|d:sect4|d:sect5|d:refentry|d:colophon|d:bibliodiv[d:title]|d:setindex|d:index" mode="ncx"/>
574
+ </xsl:element>
575
+
576
+ </xsl:template>
577
+
578
+ <xsl:template match="*" mode="opf.metadata">
579
+ <!-- override if you care -->
580
+ </xsl:template>
581
+
582
+ <xsl:template match="d:authorgroup" mode="opf.metadata">
583
+ <xsl:apply-templates select="d:author|d:corpauthor" mode="opf.metadata"/>
584
+ </xsl:template>
585
+
586
+ <xsl:template match="d:author|d:corpauthor" mode="opf.metadata">
587
+ <xsl:variable name="n">
588
+ <xsl:call-template name="person.name">
589
+ <xsl:with-param name="node" select="."/>
590
+ </xsl:call-template>
591
+ </xsl:variable>
592
+ <xsl:element name="dc:creator">
593
+ <xsl:attribute name="opf:file-as">
594
+ <xsl:variable name="attvalue">
595
+ <xsl:call-template name="person.name.last-first">
596
+ <xsl:with-param name="node" select="."/>
597
+ </xsl:call-template>
598
+ </xsl:variable>
599
+ <xsl:value-of select="$attvalue"/>
600
+ </xsl:attribute>
601
+ <xsl:value-of select="normalize-space(string($n))"/>
602
+ </xsl:element>
603
+ </xsl:template>
604
+
605
+ <xsl:template match="d:date" mode="opf.metadata">
606
+ <xsl:element name="dc:date">
607
+ <xsl:choose>
608
+ <xsl:when test="processing-instruction('dbtimestamp')">
609
+ <xsl:call-template name="datetime.format">
610
+ <xsl:with-param name="date">
611
+ <xsl:choose>
612
+ <xsl:when test="function-available('date:date-time')">
613
+ <xsl:value-of select="date:date-time()"/>
614
+ </xsl:when>
615
+ <xsl:when test="function-available('date:dateTime')">
616
+ <!-- Xalan quirk -->
617
+ <xsl:value-of select="date:dateTime()"/>
618
+ </xsl:when>
619
+ </xsl:choose>
620
+ </xsl:with-param>
621
+ <!-- We need an ISO date -->
622
+ <xsl:with-param name="format">Y-m-d</xsl:with-param>
623
+ </xsl:call-template>
624
+ </xsl:when>
625
+ <xsl:otherwise>
626
+ <xsl:value-of select="normalize-space(string(.))"/>
627
+ </xsl:otherwise>
628
+ </xsl:choose>
629
+ </xsl:element>
630
+ </xsl:template>
631
+
632
+
633
+ <!-- Space separate the compontents of the abstract (dropping the inline markup, sadly) -->
634
+ <xsl:template match="d:abstract" mode="opf.metadata">
635
+ <xsl:element name="dc:description">
636
+ <xsl:for-each select="d:formalpara|d:para|d:simpara|d:title">
637
+ <xsl:choose>
638
+ <xsl:when test="self::d:formalpara">
639
+ <xsl:value-of select="normalize-space(string(d:title))"/>
640
+ <xsl:text>: </xsl:text>
641
+ <xsl:value-of select="normalize-space(string(d:para))"/>
642
+ </xsl:when>
643
+ <xsl:otherwise>
644
+ <xsl:value-of select="normalize-space(string(.))"/>
645
+ </xsl:otherwise>
646
+ </xsl:choose>
647
+ <xsl:if test="self::d:title">
648
+ <xsl:text>:</xsl:text>
649
+ </xsl:if>
650
+ <xsl:if test="not(position() = last())">
651
+ <xsl:text> </xsl:text>
652
+ </xsl:if>
653
+ </xsl:for-each>
654
+ </xsl:element>
655
+ </xsl:template>
656
+
657
+ <xsl:template match="d:subjectset" mode="opf.metadata">
658
+ <xsl:apply-templates select="d:subject/d:subjectterm" mode="opf.metadata"/>
659
+ </xsl:template>
660
+
661
+ <xsl:template match="d:subjectterm" mode="opf.metadata">
662
+ <xsl:element name="dc:subject">
663
+ <xsl:value-of select="normalize-space(string(.))"/>
664
+ </xsl:element>
665
+ </xsl:template>
666
+
667
+ <xsl:template match="d:publisher" mode="opf.metadata">
668
+ <xsl:apply-templates select="d:publishername" mode="opf.metadata"/>
669
+ </xsl:template>
670
+
671
+ <xsl:template match="d:publishername" mode="opf.metadata">
672
+ <xsl:element name="dc:publisher">
673
+ <xsl:value-of select="normalize-space(string(.))"/>
674
+ </xsl:element>
675
+ </xsl:template>
676
+
677
+ <xsl:template match="d:copyright" mode="opf.metadata">
678
+ <xsl:variable name="copyright.date">
679
+ <xsl:call-template name="copyright.years">
680
+ <xsl:with-param name="years" select="d:year"/>
681
+ <xsl:with-param name="print.ranges" select="$make.year.ranges"/>
682
+ <xsl:with-param name="single.year.ranges" select="$make.single.year.ranges"/>
683
+ </xsl:call-template>
684
+ </xsl:variable>
685
+ <xsl:if test="not(../d:date)">
686
+ <xsl:element name="dc:date">
687
+ <xsl:call-template name="copyright.years">
688
+ <xsl:with-param name="years" select="d:year[last()]"/>
689
+ <xsl:with-param name="print.ranges" select="0"/>
690
+ <xsl:with-param name="single.year.ranges" select="0"/>
691
+ </xsl:call-template>
692
+ </xsl:element>
693
+ </xsl:if>
694
+ <xsl:element name="dc:rights">
695
+ <xsl:call-template name="gentext">
696
+ <xsl:with-param name="key" select="'Copyright'"/>
697
+ </xsl:call-template>
698
+ <xsl:call-template name="gentext.space"/>
699
+ <xsl:text>&#x00A9;</xsl:text>
700
+ <xsl:call-template name="gentext.space"/>
701
+ <xsl:value-of select="$copyright.date"/>
702
+ <xsl:call-template name="gentext.space"/>
703
+ <xsl:apply-templates select="d:holder" mode="titlepage.mode"/>
704
+ </xsl:element>
705
+ </xsl:template>
706
+
707
+ <xsl:template name="opf.guide">
708
+ <xsl:variable name="info" select="*/*[contains(local-name(.), 'info')][1]"/>
709
+
710
+ <xsl:if test="contains($toc.params, 'toc') or
711
+ $info/d:cover or
712
+ $info//d:mediaobject[@role='cover' or ancestor::d:cover]">
713
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="guide">
714
+ <xsl:if test="$info/d:cover or $info//d:mediaobject[@role='cover' or ancestor::d:cover]">
715
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="reference">
716
+ <xsl:attribute name="href">
717
+ <xsl:value-of select="$epub.cover.html" />
718
+ </xsl:attribute>
719
+ <xsl:attribute name="type">cover</xsl:attribute>
720
+ <xsl:attribute name="title">Cover</xsl:attribute>
721
+ </xsl:element>
722
+ </xsl:if>
723
+
724
+ <xsl:if test="contains($toc.params, 'toc')">
725
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="reference">
726
+ <xsl:attribute name="href">
727
+ <xsl:call-template name="toc-href">
728
+ <xsl:with-param name="node" select="/*"/>
729
+ </xsl:call-template>
730
+ </xsl:attribute>
731
+ <xsl:attribute name="type">toc</xsl:attribute>
732
+ <xsl:attribute name="title">Table of Contents</xsl:attribute>
733
+ </xsl:element>
734
+ </xsl:if>
735
+ </xsl:element>
736
+ </xsl:if>
737
+ </xsl:template>
738
+
739
+ <xsl:template name="opf.spine">
740
+ <xsl:variable name="info" select="*/*[contains(local-name(.), 'info')][1]"/>
741
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="spine">
742
+ <xsl:attribute name="toc">
743
+ <xsl:value-of select="$epub.ncx.toc.id"/>
744
+ </xsl:attribute>
745
+
746
+ <xsl:call-template name="spine.cover"/>
747
+
748
+ <xsl:if test="contains($toc.params, 'toc')">
749
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
750
+ <xsl:attribute name="idref"> <xsl:value-of select="$epub.html.toc.id"/> </xsl:attribute>
751
+ <xsl:attribute name="linear">yes</xsl:attribute>
752
+ </xsl:element>
753
+ </xsl:if>
754
+
755
+ <!-- TODO: be nice to have a idref="titlepage" here -->
756
+ <xsl:choose>
757
+ <xsl:when test="$root.is.a.chunk != '0'">
758
+ <xsl:apply-templates select="/*" mode="opf.spine"/>
759
+ </xsl:when>
760
+ <xsl:otherwise>
761
+ <xsl:apply-templates select="/*/*" mode="opf.spine"/>
762
+ </xsl:otherwise>
763
+ </xsl:choose>
764
+ </xsl:element>
765
+ </xsl:template>
766
+
767
+ <xsl:template name="spine.cover">
768
+ <xsl:variable name="info" select="*/*[contains(local-name(.), 'info')][1]"/>
769
+ <xsl:variable name="cover.image"
770
+ select="$info//d:mediaobject[@role='cover' or ancestor::d:cover]"/>
771
+
772
+ <xsl:if test="$cover.image">
773
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
774
+ <xsl:attribute name="idref">
775
+ <xsl:value-of select="$epub.cover.id"/>
776
+ </xsl:attribute>
777
+ <xsl:attribute name="linear">
778
+ <xsl:choose>
779
+ <xsl:when test="$epub.cover.linear">
780
+ <xsl:text>yes</xsl:text>
781
+ </xsl:when>
782
+ <xsl:otherwise>no</xsl:otherwise>
783
+ </xsl:choose>
784
+ </xsl:attribute>
785
+ </xsl:element>
786
+ </xsl:if>
787
+ </xsl:template>
788
+
789
+
790
+ <xsl:template match="*" mode="opf.spine">
791
+ <xsl:variable name="is.chunk">
792
+ <xsl:call-template name="chunk">
793
+ <xsl:with-param name="node" select="."/>
794
+ </xsl:call-template>
795
+ </xsl:variable>
796
+
797
+ <xsl:if test="$is.chunk != 0">
798
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
799
+ <xsl:attribute name="idref">
800
+ <xsl:value-of select="generate-id(.)"/>
801
+ </xsl:attribute>
802
+ </xsl:element>
803
+ <xsl:apply-templates select="*" mode="opf.spine"/>
804
+ </xsl:if>
805
+ </xsl:template>
806
+
807
+ <xsl:template name="opf.manifest">
808
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="manifest">
809
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
810
+ <xsl:attribute name="id"> <xsl:value-of select="$epub.ncx.toc.id"/> </xsl:attribute>
811
+ <xsl:attribute name="media-type">application/x-dtbncx+xml</xsl:attribute>
812
+ <xsl:attribute name="href"><xsl:value-of select="$epub.ncx.filename"/> </xsl:attribute>
813
+ </xsl:element>
814
+
815
+ <xsl:if test="contains($toc.params, 'toc')">
816
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
817
+ <xsl:attribute name="id"> <xsl:value-of select="$epub.html.toc.id"/> </xsl:attribute>
818
+ <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
819
+ <xsl:attribute name="href">
820
+ <xsl:call-template name="toc-href">
821
+ <xsl:with-param name="node" select="/*"/>
822
+ </xsl:call-template>
823
+ </xsl:attribute>
824
+ </xsl:element>
825
+ </xsl:if>
826
+
827
+ <xsl:if test="$html.stylesheet != ''">
828
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
829
+ <xsl:attribute name="media-type">text/css</xsl:attribute>
830
+ <xsl:attribute name="id">css</xsl:attribute>
831
+ <xsl:attribute name="href"><xsl:value-of select="$html.stylesheet"/></xsl:attribute>
832
+ </xsl:element>
833
+ </xsl:if>
834
+
835
+ <xsl:if test="/*/*[d:cover or contains(name(.), 'info')]//d:mediaobject[@role='cover' or ancestor::d:cover]">
836
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
837
+ <xsl:attribute name="id"> <xsl:value-of select="$epub.cover.id"/> </xsl:attribute>
838
+ <xsl:attribute name="href">
839
+ <xsl:value-of select="$epub.cover.html"/>
840
+ </xsl:attribute>
841
+ <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
842
+ </xsl:element>
843
+ </xsl:if>
844
+
845
+ <xsl:choose>
846
+ <xsl:when test="$epub.embedded.fonts != '' and not(contains($epub.embedded.fonts, ','))">
847
+ <xsl:call-template name="embedded-font-item">
848
+ <xsl:with-param name="font.file" select="$epub.embedded.fonts"/> <!-- There is just one -->
849
+ </xsl:call-template>
850
+ </xsl:when>
851
+ <xsl:when test="$epub.embedded.fonts != ''">
852
+ <xsl:variable name="font.file.tokens" select="str:tokenize($epub.embedded.fonts, ',')"/>
853
+ <xsl:for-each select="exsl:node-set($font.file.tokens)">
854
+ <xsl:call-template name="embedded-font-item">
855
+ <xsl:with-param name="font.file" select="."/>
856
+ <xsl:with-param name="font.order" select="position()"/>
857
+ </xsl:call-template>
858
+ </xsl:for-each>
859
+ </xsl:when>
860
+ </xsl:choose>
861
+
862
+ <!-- TODO: be nice to have a id="titlepage" here -->
863
+ <xsl:apply-templates select="//d:part|
864
+ //d:book[*[last()][self::d:bookinfo]]|
865
+ //d:book[d:bookinfo]|
866
+ //d:book[*[last()][self::d:info]]|
867
+ //d:book[d:info]|
868
+ /d:set|
869
+ /d:set/d:book|
870
+ //d:reference|
871
+ //d:preface|
872
+ //d:chapter|
873
+ //d:bibliography|
874
+ //d:appendix|
875
+ //d:article|
876
+ //d:glossary|
877
+ //d:section|
878
+ //d:sect1|
879
+ //d:sect2|
880
+ //d:sect3|
881
+ //d:sect4|
882
+ //d:sect5|
883
+ //d:refentry|
884
+ //d:colophon|
885
+ //d:bibliodiv[d:title]|
886
+ //d:index|
887
+ //d:setindex|
888
+ //d:graphic|
889
+ //d:inlinegraphic|
890
+ //d:mediaobject|
891
+ //d:mediaobjectco|
892
+ //d:inlinemediaobject"
893
+ mode="opf.manifest"/>
894
+ <xsl:call-template name="opf.calloutlist"/>
895
+ </xsl:element>
896
+ </xsl:template>
897
+
898
+ <xsl:template name="opf.calloutlist">
899
+ <xsl:variable name="format">
900
+ <xsl:call-template name="guess-media-type">
901
+ <xsl:with-param name="ext" select="$callout.graphics.extension"/>
902
+ </xsl:call-template>
903
+ </xsl:variable>
904
+ <xsl:if test="$callout.graphics != 0 and (//d:calloutlist|//d:co)">
905
+ <xsl:call-template name="opf.reference.callout">
906
+ <xsl:with-param name="conum" select="1"/>
907
+ <xsl:with-param name="format" select="$format"/>
908
+ </xsl:call-template>
909
+ </xsl:if>
910
+ </xsl:template>
911
+
912
+ <xsl:template name="opf.reference.callout">
913
+ <xsl:param name="conum"/>
914
+ <xsl:param name="format"/>
915
+
916
+ <xsl:variable name="filename" select="concat($callout.graphics.path, $conum, $callout.graphics.extension)"/>
917
+
918
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
919
+ <xsl:attribute name="id"> <xsl:value-of select="concat(generate-id(.), 'callout', $conum)"/> </xsl:attribute>
920
+ <xsl:attribute name="href"> <xsl:value-of select="$filename"/> </xsl:attribute>
921
+ <xsl:attribute name="media-type">
922
+ <xsl:value-of select="$format"/>
923
+ </xsl:attribute>
924
+ </xsl:element>
925
+ <xsl:if test="($conum &lt; $callout.graphics.number.limit)">
926
+ <xsl:call-template name="opf.reference.callout">
927
+ <xsl:with-param name="conum" select="$conum + 1"/>
928
+ <xsl:with-param name="format" select="$format"/>
929
+ </xsl:call-template>
930
+ </xsl:if>
931
+ </xsl:template>
932
+
933
+ <xsl:template name="guess-media-type">
934
+ <xsl:param name="ext"></xsl:param>
935
+ <xsl:choose>
936
+ <xsl:when test="contains($ext, '.gif')">
937
+ <xsl:text>image/gif</xsl:text>
938
+ </xsl:when>
939
+ <xsl:when test="contains($ext, 'GIF')">
940
+ <xsl:text>image/gif</xsl:text>
941
+ </xsl:when>
942
+ <xsl:when test="contains($ext, '.png')">
943
+ <xsl:text>image/png</xsl:text>
944
+ </xsl:when>
945
+ <xsl:when test="contains($ext, 'PNG')">
946
+ <xsl:text>image/png</xsl:text>
947
+ </xsl:when>
948
+ <xsl:when test="contains($ext, '.jpeg')">
949
+ <xsl:text>image/jpeg</xsl:text>
950
+ </xsl:when>
951
+ <xsl:when test="contains($ext, 'JPEG')">
952
+ <xsl:text>image/jpeg</xsl:text>
953
+ </xsl:when>
954
+ <xsl:when test="contains($ext, '.jpg')">
955
+ <xsl:text>image/jpeg</xsl:text>
956
+ </xsl:when>
957
+ <xsl:when test="contains($ext, 'JPG')">
958
+ <xsl:text>image/jpeg</xsl:text>
959
+ </xsl:when>
960
+ <xsl:when test="contains($ext, '.svg')">
961
+ <xsl:text>image/svg+xml</xsl:text>
962
+ </xsl:when>
963
+ <xsl:when test="contains($ext, 'SVG')">
964
+ <xsl:text>image/svg+xml</xsl:text>
965
+ </xsl:when>
966
+ <xsl:otherwise>
967
+ <!-- we failed -->
968
+ <xsl:text></xsl:text>
969
+ </xsl:otherwise>
970
+ </xsl:choose>
971
+ </xsl:template>
972
+
973
+ <xsl:template match="d:mediaobject|
974
+ d:mediaobjectco|
975
+ d:inlinemediaobject"
976
+ mode="opf.manifest">
977
+
978
+ <xsl:variable name="olist" select="d:imageobject|d:imageobjectco |d:videoobject|d:audioobject |d:textobject"/>
979
+
980
+ <xsl:variable name="object.index">
981
+ <xsl:call-template name="select.mediaobject.index">
982
+ <xsl:with-param name="olist" select="$olist"/>
983
+ <xsl:with-param name="count" select="1"/>
984
+ </xsl:call-template>
985
+ </xsl:variable>
986
+
987
+ <xsl:variable name="object" select="$olist[position() = $object.index]"/>
988
+
989
+ <xsl:choose>
990
+ <xsl:when test="$object/descendant::d:imagedata[@format = 'GIF' or
991
+ @format = 'GIF87a' or
992
+ @format = 'GIF89a' or
993
+ @format = 'JPEG' or
994
+ @format = 'JPG' or
995
+ @format = 'PNG' or
996
+ @format = 'SVG']">
997
+ <xsl:apply-templates select="$object[descendant::d:imagedata[@format = 'GIF' or
998
+ @format = 'GIF87a' or
999
+ @format = 'GIF89a' or
1000
+ @format = 'JPEG' or
1001
+ @format = 'JPG' or
1002
+ @format = 'PNG' or
1003
+ @format = 'SVG']][1]/d:imagedata"
1004
+ mode="opf.manifest"/>
1005
+ </xsl:when>
1006
+ <xsl:otherwise>
1007
+ <xsl:apply-templates select="$object/d:imagedata[1]"
1008
+ mode="opf.manifest"/>
1009
+ </xsl:otherwise>
1010
+ </xsl:choose>
1011
+ </xsl:template>
1012
+
1013
+ <xsl:template match="d:cover/d:mediaobject|
1014
+ d:mediaobject[@role='cover']"
1015
+ mode="opf.manifest">
1016
+ <xsl:choose>
1017
+ <xsl:when test="d:imageobject[@role='front-large']">
1018
+ <xsl:apply-templates select="d:imageobject[@role='front-large']/d:imagedata"
1019
+ mode="opf.manifest"/>
1020
+ </xsl:when>
1021
+ <xsl:otherwise>
1022
+ <xsl:apply-templates select="d:imageobject/d:imagedata[1]"
1023
+ mode="opf.manifest"/>
1024
+ </xsl:otherwise>
1025
+ </xsl:choose>
1026
+ </xsl:template>
1027
+
1028
+ <xsl:template match="d:mediaobjectco"
1029
+ mode="opf.manifest">
1030
+ <xsl:message>WARNING: mediaobjectco almost certainly will not render as expected in .epub!</xsl:message>
1031
+ <xsl:apply-templates select="d:imageobjectco/d:imageobject/d:imagedata"
1032
+ mode="opf.manifest"/>
1033
+ </xsl:template>
1034
+
1035
+ <!-- TODO: Barf (xsl:message terminate=yes) if you find a graphic with no reasonable format or a mediaobject w/o same? [option to not die?] -->
1036
+
1037
+ <!-- wish I had XSLT2 ...-->
1038
+ <!-- TODO: priority a hack -->
1039
+ <xsl:template match="d:graphic[not(@format)]|
1040
+ d:inlinegraphic[not(@format)]|
1041
+ d:imagedata[not(@format)]"
1042
+ mode="opf.manifest">
1043
+ <xsl:variable name="filename">
1044
+ <xsl:choose>
1045
+ <xsl:when test="contains(name(.), 'graphic')">
1046
+ <xsl:choose>
1047
+ <xsl:when test="@entityref">
1048
+ <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
1049
+ </xsl:when>
1050
+ <xsl:otherwise>
1051
+ <xsl:apply-templates select="@fileref"/>
1052
+ </xsl:otherwise>
1053
+ </xsl:choose>
1054
+ </xsl:when>
1055
+ <xsl:otherwise>
1056
+ <xsl:call-template name="mediaobject.filename">
1057
+ <xsl:with-param name="object" select=".."/>
1058
+ </xsl:call-template>
1059
+ </xsl:otherwise>
1060
+ </xsl:choose>
1061
+ </xsl:variable>
1062
+ <xsl:variable name="format">
1063
+ <xsl:call-template name="guess-media-type">
1064
+ <xsl:with-param name="ext" select="@fileref"/>
1065
+ </xsl:call-template>
1066
+ </xsl:variable>
1067
+ <xsl:variable name="fr" select="@fileref"/>
1068
+ <xsl:if test="$format != ''">
1069
+ <!-- only do this if we're the first file to match -->
1070
+ <!-- TODO: Why can't this be simple equality?? (I couldn't get it to work) -->
1071
+ <xsl:if test="generate-id(.) = generate-id(key('image-filerefs', $fr)[1])">
1072
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
1073
+ <xsl:attribute name="id">
1074
+ <xsl:choose>
1075
+ <xsl:when test="ancestor::d:mediaobject[@role='cover'] and parent::*[@role='front-large']">
1076
+ <xsl:value-of select="$epub.cover.image.id"/>
1077
+ </xsl:when>
1078
+ <xsl:when test="ancestor::d:mediaobject[@role='cover'] and (count(ancestor::d:mediaobject//d:imageobject) = 1)">
1079
+ <xsl:value-of select="$epub.cover.image.id"/>
1080
+ </xsl:when>
1081
+ <xsl:when test="ancestor::d:cover">
1082
+ <xsl:value-of select="$epub.cover.image.id"/>
1083
+ </xsl:when>
1084
+ <xsl:otherwise>
1085
+ <xsl:value-of select="generate-id(.)"/>
1086
+ </xsl:otherwise>
1087
+ </xsl:choose>
1088
+ </xsl:attribute>
1089
+ <xsl:attribute name="href"> <xsl:value-of select="$filename"/> </xsl:attribute>
1090
+ <xsl:attribute name="media-type">
1091
+ <xsl:value-of select="$format"/>
1092
+ </xsl:attribute>
1093
+ </xsl:element>
1094
+ </xsl:if>
1095
+ </xsl:if>
1096
+ </xsl:template>
1097
+
1098
+ <!-- Note: Selection of the first interesting imagedata is done in the select -->
1099
+ <xsl:template match="d:graphic[@format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or @format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or @format = 'SVG']|
1100
+ d:inlinegraphic[@format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or @format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or @format = 'SVG']|
1101
+ d:imagedata[@format]"
1102
+ mode="opf.manifest">
1103
+ <xsl:variable name="filename">
1104
+ <xsl:choose>
1105
+ <xsl:when test="contains(name(.), 'graphic')">
1106
+ <xsl:choose>
1107
+ <xsl:when test="@entityref">
1108
+ <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
1109
+ </xsl:when>
1110
+ <xsl:otherwise>
1111
+ <xsl:apply-templates select="@fileref"/>
1112
+ </xsl:otherwise>
1113
+ </xsl:choose>
1114
+ </xsl:when>
1115
+ <xsl:otherwise>
1116
+ <xsl:call-template name="mediaobject.filename">
1117
+ <xsl:with-param name="object" select=".."/>
1118
+ </xsl:call-template>
1119
+ </xsl:otherwise>
1120
+ </xsl:choose>
1121
+ </xsl:variable>
1122
+ <xsl:variable name="fr" select="@fileref"/>
1123
+ <!-- only do this if we're the first file to match -->
1124
+ <!-- TODO: Why can't this be simple equality?? (I couldn't get it to work) -->
1125
+ <xsl:if test="generate-id(.) = generate-id(key('image-filerefs', $fr)[1])">
1126
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
1127
+ <xsl:attribute name="id">
1128
+ <xsl:choose>
1129
+ <xsl:when test="ancestor::d:mediaobject[@role='cover'] and parent::*[@role='front-large']">
1130
+ <xsl:value-of select="$epub.cover.image.id"/>
1131
+ </xsl:when>
1132
+ <xsl:when test="ancestor::d:mediaobject[@role='cover'] and (count(ancestor::d:mediaobject//d:imageobject) = 1)">
1133
+ <xsl:value-of select="$epub.cover.image.id"/>
1134
+ </xsl:when>
1135
+ <xsl:when test="ancestor::d:cover">
1136
+ <xsl:value-of select="$epub.cover.image.id"/>
1137
+ </xsl:when>
1138
+ <xsl:otherwise>
1139
+ <xsl:value-of select="generate-id(.)"/>
1140
+ </xsl:otherwise>
1141
+ </xsl:choose>
1142
+ </xsl:attribute>
1143
+ <xsl:attribute name="href"> <xsl:value-of select="$filename"/> </xsl:attribute>
1144
+ <xsl:attribute name="media-type">
1145
+ <xsl:call-template name="guess-media-type">
1146
+ <xsl:with-param name="ext" select="@format"/>
1147
+ </xsl:call-template>
1148
+ </xsl:attribute>
1149
+ </xsl:element>
1150
+ </xsl:if>
1151
+ </xsl:template>
1152
+
1153
+ <!-- Warning: While the test indicate this match list is accurate, it may
1154
+ need further tweaking to ensure _never_ dropping generated content (XHTML)
1155
+ from the manifest (OPF file) -->
1156
+ <xsl:template
1157
+ match="d:set|
1158
+ d:book[parent::d:set]|
1159
+ d:book[*[last()][self::d:bookinfo]]|
1160
+ d:book[d:bookinfo]|
1161
+ d:book[*[last()][self::d:info]]|
1162
+ d:book[d:info]|
1163
+ d:article|
1164
+ d:part|
1165
+ d:reference|
1166
+ d:preface|
1167
+ d:chapter|
1168
+ d:bibliography|
1169
+ d:appendix|
1170
+ d:glossary|
1171
+ d:section|
1172
+ d:sect1|
1173
+ d:sect2|
1174
+ d:sect3|
1175
+ d:sect4|
1176
+ d:sect5|
1177
+ d:refentry|
1178
+ d:colophon|
1179
+ d:bibliodiv[d:title]|
1180
+ d:setindex|
1181
+ d:index"
1182
+ mode="opf.manifest">
1183
+ <xsl:variable name="href">
1184
+ <xsl:call-template name="href.target.with.base.dir">
1185
+ <xsl:with-param name="context" select="/" />
1186
+ <!-- Generate links relative to the location of root file/toc.xml file -->
1187
+ </xsl:call-template>
1188
+ </xsl:variable>
1189
+
1190
+ <xsl:variable name="id">
1191
+ <xsl:value-of select="generate-id(.)"/>
1192
+ </xsl:variable>
1193
+
1194
+ <xsl:variable name="is.chunk">
1195
+ <xsl:call-template name="chunk">
1196
+ <xsl:with-param name="node" select="."/>
1197
+ </xsl:call-template>
1198
+ </xsl:variable>
1199
+
1200
+ <xsl:if test="$is.chunk != 0">
1201
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
1202
+ <xsl:attribute name="id"> <xsl:value-of select="$id"/> </xsl:attribute>
1203
+ <xsl:attribute name="href"> <xsl:value-of select="$href"/> </xsl:attribute>
1204
+ <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
1205
+ </xsl:element>
1206
+ </xsl:if>
1207
+ </xsl:template>
1208
+
1209
+ <xsl:template match="text()" mode="ncx" />
1210
+
1211
+ <xsl:template name="html.head">
1212
+ <xsl:param name="prev" select="/d:foo"/>
1213
+ <xsl:param name="next" select="/d:foo"/>
1214
+ <xsl:variable name="this" select="."/>
1215
+ <xsl:variable name="home" select="/*[1]"/>
1216
+ <xsl:variable name="up" select="parent::*"/>
1217
+
1218
+ <head xmlns="http://www.w3.org/1999/xhtml">
1219
+ <xsl:call-template name="system.head.content"/>
1220
+ <xsl:call-template name="head.content"/>
1221
+
1222
+ <xsl:call-template name="user.head.content"/>
1223
+ </head>
1224
+ </xsl:template>
1225
+
1226
+ <!-- OVERRIDES xhtml-1_1/graphics.xsl -->
1227
+ <!-- we can't deal with no img/@alt, because it's required. Try grabbing a title before it instead (hopefully meaningful) -->
1228
+ <xsl:template name="process.image.attributes">
1229
+ <xsl:param name="alt"/>
1230
+ <xsl:param name="html.width"/>
1231
+ <xsl:param name="html.depth"/>
1232
+ <xsl:param name="longdesc"/>
1233
+ <xsl:param name="scale"/>
1234
+ <xsl:param name="scalefit"/>
1235
+ <xsl:param name="scaled.contentdepth"/>
1236
+ <xsl:param name="scaled.contentwidth"/>
1237
+ <xsl:param name="viewport"/>
1238
+
1239
+ <xsl:choose>
1240
+ <xsl:when test="@contentwidth or @contentdepth">
1241
+ <!-- ignore @width/@depth, @scale, and @scalefit if specified -->
1242
+ <xsl:if test="@contentwidth and $scaled.contentwidth != ''">
1243
+ <xsl:attribute name="width">
1244
+ <xsl:value-of select="$scaled.contentwidth"/>
1245
+ </xsl:attribute>
1246
+ </xsl:if>
1247
+ <xsl:if test="@contentdepth and $scaled.contentdepth != ''">
1248
+ <xsl:attribute name="height">
1249
+ <xsl:value-of select="$scaled.contentdepth"/>
1250
+ </xsl:attribute>
1251
+ </xsl:if>
1252
+ </xsl:when>
1253
+
1254
+ <xsl:when test="number($scale) != 1.0">
1255
+ <!-- scaling is always uniform, so we only have to specify one dimension -->
1256
+ <!-- ignore @scalefit if specified -->
1257
+ <xsl:attribute name="width">
1258
+ <xsl:value-of select="$scaled.contentwidth"/>
1259
+ </xsl:attribute>
1260
+ </xsl:when>
1261
+
1262
+ <xsl:when test="$scalefit != 0">
1263
+ <xsl:choose>
1264
+ <xsl:when test="contains($html.width, '%')">
1265
+ <xsl:choose>
1266
+ <xsl:when test="$viewport != 0">
1267
+ <!-- The *viewport* will be scaled, so use 100% here! -->
1268
+ <xsl:attribute name="width">
1269
+ <xsl:value-of select="'100%'"/>
1270
+ </xsl:attribute>
1271
+ </xsl:when>
1272
+ <xsl:otherwise>
1273
+ <xsl:attribute name="width">
1274
+ <xsl:value-of select="$html.width"/>
1275
+ </xsl:attribute>
1276
+ </xsl:otherwise>
1277
+ </xsl:choose>
1278
+ </xsl:when>
1279
+
1280
+ <xsl:when test="contains($html.depth, '%')">
1281
+ <!-- HTML doesn't deal with this case very well...do nothing -->
1282
+ </xsl:when>
1283
+
1284
+ <xsl:when test="$scaled.contentwidth != '' and $html.width != '' and $scaled.contentdepth != '' and $html.depth != ''">
1285
+ <!-- scalefit should not be anamorphic; figure out which direction -->
1286
+ <!-- has the limiting scale factor and scale in that direction -->
1287
+ <xsl:choose>
1288
+ <xsl:when test="$html.width div $scaled.contentwidth &gt; $html.depth div $scaled.contentdepth">
1289
+ <xsl:attribute name="height">
1290
+ <xsl:value-of select="$html.depth"/>
1291
+ </xsl:attribute>
1292
+ </xsl:when>
1293
+ <xsl:otherwise>
1294
+ <xsl:attribute name="width">
1295
+ <xsl:value-of select="$html.width"/>
1296
+ </xsl:attribute>
1297
+ </xsl:otherwise>
1298
+ </xsl:choose>
1299
+ </xsl:when>
1300
+
1301
+ <xsl:when test="$scaled.contentwidth != '' and $html.width != ''">
1302
+ <xsl:attribute name="width">
1303
+ <xsl:value-of select="$html.width"/>
1304
+ </xsl:attribute>
1305
+ </xsl:when>
1306
+
1307
+ <xsl:when test="$scaled.contentdepth != '' and $html.depth != ''">
1308
+ <xsl:attribute name="height">
1309
+ <xsl:value-of select="$html.depth"/>
1310
+ </xsl:attribute>
1311
+ </xsl:when>
1312
+ </xsl:choose>
1313
+ </xsl:when>
1314
+ </xsl:choose>
1315
+
1316
+ <!-- AN OVERRIDE -->
1317
+ <xsl:if test="not(@format ='SVG')">
1318
+ <xsl:attribute name="alt">
1319
+ <xsl:choose>
1320
+ <xsl:when test="$alt != ''">
1321
+ <xsl:value-of select="normalize-space($alt)"/>
1322
+ </xsl:when>
1323
+ <xsl:when test="preceding::d:title[1]">
1324
+ <xsl:value-of select="normalize-space(preceding::d:title[1])"/>
1325
+ </xsl:when>
1326
+ <xsl:otherwise>
1327
+ <xsl:text>(missing alt)</xsl:text>
1328
+ </xsl:otherwise>
1329
+ </xsl:choose>
1330
+ </xsl:attribute>
1331
+ </xsl:if>
1332
+ <!-- END OF OVERRIDE -->
1333
+
1334
+ <xsl:if test="$longdesc != ''">
1335
+ <xsl:attribute name="longdesc">
1336
+ <xsl:value-of select="$longdesc"/>
1337
+ </xsl:attribute>
1338
+ </xsl:if>
1339
+
1340
+ <xsl:if test="@align and $viewport = 0">
1341
+ <xsl:attribute name="style"><xsl:text>text-align: </xsl:text>
1342
+ <xsl:choose>
1343
+ <xsl:when test="@align = 'center'">middle</xsl:when>
1344
+ <xsl:otherwise>
1345
+ <xsl:value-of select="@align"/>
1346
+ </xsl:otherwise>
1347
+ </xsl:choose>
1348
+ </xsl:attribute>
1349
+ </xsl:if>
1350
+ </xsl:template>
1351
+
1352
+ <!-- OVERRIDES xhtml-1_1/chunk-common.xsl -->
1353
+ <!-- make a bibliography always a chunk -->
1354
+ <xsl:template name="chunk">
1355
+ <xsl:param name="node" select="."/>
1356
+ <!-- returns 1 if $node is a chunk -->
1357
+
1358
+ <!-- ==================================================================== -->
1359
+ <!-- What's a chunk?
1360
+
1361
+ The root element
1362
+ appendix
1363
+ article
1364
+ bibliography ### NO LONGER TRUE in article or part or book
1365
+ book
1366
+ chapter
1367
+ colophon
1368
+ glossary in article or part or book
1369
+ index in article or part or book
1370
+ part
1371
+ preface
1372
+ refentry
1373
+ reference
1374
+ sect{1,2,3,4,5} if position()>1 && depth < chunk.section.depth
1375
+ section if position()>1 && depth < chunk.section.depth
1376
+ set
1377
+ setindex
1378
+ -->
1379
+ <!-- ==================================================================== -->
1380
+
1381
+ <!--
1382
+ <xsl:message>
1383
+ <xsl:text>chunk: </xsl:text>
1384
+ <xsl:value-of select="name($node)"/>
1385
+ <xsl:text>(</xsl:text>
1386
+ <xsl:value-of select="$node/@id"/>
1387
+ <xsl:text>)</xsl:text>
1388
+ <xsl:text> csd: </xsl:text>
1389
+ <xsl:value-of select="$chunk.section.depth"/>
1390
+ <xsl:text> cfs: </xsl:text>
1391
+ <xsl:value-of select="$chunk.first.sections"/>
1392
+ <xsl:text> ps: </xsl:text>
1393
+ <xsl:value-of select="count($node/parent::d:section)"/>
1394
+ <xsl:text> prs: </xsl:text>
1395
+ <xsl:value-of select="count($node/preceding-sibling::d:section)"/>
1396
+ </xsl:message>
1397
+ -->
1398
+
1399
+ <xsl:choose>
1400
+ <xsl:when test="not($node/parent::*)">1</xsl:when>
1401
+
1402
+ <xsl:when test="local-name($node) = 'sect1' and $chunk.section.depth &gt;= 1 and ($chunk.first.sections != 0 or count($node/preceding-sibling::d:sect1) &gt; 0)">
1403
+ <xsl:text>1</xsl:text>
1404
+ </xsl:when>
1405
+ <xsl:when test="local-name($node) = 'sect2' and $chunk.section.depth &gt;= 2 and ($chunk.first.sections != 0 or count($node/preceding-sibling::d:sect2) &gt; 0)">
1406
+ <xsl:call-template name="chunk">
1407
+ <xsl:with-param name="node" select="$node/parent::*"/>
1408
+ </xsl:call-template>
1409
+ </xsl:when>
1410
+ <xsl:when test="local-name($node) = 'sect3' and $chunk.section.depth &gt;= 3 and ($chunk.first.sections != 0 or count($node/preceding-sibling::d:sect3) &gt; 0)">
1411
+ <xsl:call-template name="chunk">
1412
+ <xsl:with-param name="node" select="$node/parent::*"/>
1413
+ </xsl:call-template>
1414
+ </xsl:when>
1415
+ <xsl:when test="local-name($node) = 'sect4' and $chunk.section.depth &gt;= 4 and ($chunk.first.sections != 0 or count($node/preceding-sibling::d:sect4) &gt; 0)">
1416
+ <xsl:call-template name="chunk">
1417
+ <xsl:with-param name="node" select="$node/parent::*"/>
1418
+ </xsl:call-template>
1419
+ </xsl:when>
1420
+ <xsl:when test="local-name($node) = 'sect5' and $chunk.section.depth &gt;= 5 and ($chunk.first.sections != 0 or count($node/preceding-sibling::d:sect5) &gt; 0)">
1421
+ <xsl:call-template name="chunk">
1422
+ <xsl:with-param name="node" select="$node/parent::*"/>
1423
+ </xsl:call-template>
1424
+ </xsl:when>
1425
+ <xsl:when test="local-name($node) = 'section' and $chunk.section.depth &gt;= count($node/ancestor::d:section)+1 and ($chunk.first.sections != 0 or count($node/preceding-sibling::d:section) &gt; 0)">
1426
+ <xsl:call-template name="chunk">
1427
+ <xsl:with-param name="node" select="$node/parent::*"/>
1428
+ </xsl:call-template>
1429
+ </xsl:when>
1430
+
1431
+ <xsl:when test="local-name($node)='preface'">1</xsl:when>
1432
+ <xsl:when test="local-name($node)='chapter'">1</xsl:when>
1433
+ <xsl:when test="local-name($node)='appendix'">1</xsl:when>
1434
+ <xsl:when test="local-name($node)='article'">1</xsl:when>
1435
+ <xsl:when test="local-name($node)='part'">1</xsl:when>
1436
+ <xsl:when test="local-name($node)='reference'">1</xsl:when>
1437
+ <xsl:when test="local-name($node)='refentry'">1</xsl:when>
1438
+ <xsl:when test="local-name($node)='index' and ($generate.index != 0 or count($node/*) &gt; 0) and (local-name($node/parent::*) = 'article' or local-name($node/parent::*) = 'book' or local-name($node/parent::*) = 'part' )">1</xsl:when>
1439
+ <!-- AN OVERRIDE -->
1440
+ <xsl:when test="local-name($node)='bibliography'">1</xsl:when>
1441
+ <!-- END OF OVERRIDE -->
1442
+ <xsl:when test="local-name($node)='glossary' and (local-name($node/parent::*) = 'article' or local-name($node/parent::*) = 'book' or local-name($node/parent::*) = 'part' )">1</xsl:when>
1443
+ <xsl:when test="local-name($node)='colophon'">1</xsl:when>
1444
+ <xsl:when test="local-name($node)='book'">1</xsl:when>
1445
+ <xsl:when test="local-name($node)='set'">1</xsl:when>
1446
+ <xsl:when test="local-name($node)='setindex'">1</xsl:when>
1447
+ <xsl:when test="local-name($node)='legalnotice' and $generate.legalnotice.link != 0">1</xsl:when>
1448
+ <xsl:otherwise>0</xsl:otherwise>
1449
+ </xsl:choose>
1450
+ </xsl:template>
1451
+
1452
+ <!-- OVERRIDES xhtml-1_1/chunk-code.xsl -->
1453
+ <!-- Add chunking for bibliography as root element -->
1454
+ <!-- AN OVERRIDE -->
1455
+ <xsl:template match="d:set|
1456
+ d:book|
1457
+ d:part|
1458
+ d:preface|
1459
+ d:chapter|
1460
+ d:appendix|
1461
+ d:article|
1462
+ d:reference|
1463
+ d:refentry|
1464
+ d:book/d:glossary|
1465
+ d:article/d:glossary|
1466
+ d:part/d:glossary|
1467
+ d:bibliography|
1468
+ d:colophon"
1469
+ priority="1">
1470
+ <!-- END OF OVERRIDE -->
1471
+ <xsl:choose>
1472
+ <xsl:when test="$onechunk != 0 and parent::*">
1473
+ <xsl:apply-imports/>
1474
+ </xsl:when>
1475
+ <xsl:otherwise>
1476
+ <xsl:call-template name="process-chunk-element"/>
1477
+ </xsl:otherwise>
1478
+ </xsl:choose>
1479
+ </xsl:template>
1480
+
1481
+ <!-- OVERRIDES xhtml-1_1/graphics.xsl -->
1482
+ <!-- Do _NOT_ output any xlink garbage, so if you don't have
1483
+ processor with extensions, you're screwed and we're terminating -->
1484
+ <xsl:template match="d:inlinegraphic">
1485
+ <xsl:variable name="filename">
1486
+ <xsl:choose>
1487
+ <xsl:when test="@entityref">
1488
+ <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
1489
+ </xsl:when>
1490
+ <xsl:otherwise>
1491
+ <xsl:apply-templates select="@fileref"/>
1492
+ </xsl:otherwise>
1493
+ </xsl:choose>
1494
+ </xsl:variable>
1495
+
1496
+ <xsl:call-template name="anchor"/>
1497
+
1498
+ <xsl:choose>
1499
+ <xsl:when test="@format='linespecific'">
1500
+ <xsl:choose>
1501
+ <xsl:when test="$use.extensions != '0' and $textinsert.extension != '0'">
1502
+ <xsl:choose>
1503
+ <xsl:when test="element-available('stext:insertfile')">
1504
+ <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
1505
+ </xsl:when>
1506
+ <xsl:when test="element-available('xtext:insertfile')">
1507
+ <xtext:insertfile href="{$filename}"/>
1508
+ </xsl:when>
1509
+ <xsl:otherwise>
1510
+ <xsl:message terminate="yes">
1511
+ <xsl:text>No insertfile extension available.</xsl:text>
1512
+ </xsl:message>
1513
+ </xsl:otherwise>
1514
+ </xsl:choose>
1515
+ </xsl:when>
1516
+ <xsl:otherwise>
1517
+ <!-- AN OVERRIDE -->
1518
+ <xsl:message terminate="yes">
1519
+ <xsl:text>No insertfile extension available. Use a different processor (with extensions) or turn on $use.extensions and $textinsert.extension (see docs for more). </xsl:text>
1520
+ </xsl:message>
1521
+ <!-- END OF OVERRIDE -->
1522
+ </xsl:otherwise>
1523
+ </xsl:choose>
1524
+ </xsl:when>
1525
+ <xsl:otherwise>
1526
+ <xsl:call-template name="process.image"/>
1527
+ </xsl:otherwise>
1528
+ </xsl:choose>
1529
+ </xsl:template>
1530
+
1531
+ <xsl:template name="cover">
1532
+ <xsl:apply-templates select="/*/*[contains(name(.), 'info')]//d:mediaobject[@role='cover' or ancestor::d:cover]"/>
1533
+ </xsl:template>
1534
+
1535
+ <xsl:template match="/*/*[d:cover or contains(name(.), 'info')]//d:mediaobject[@role='cover' or ancestor::d:cover]">
1536
+ <xsl:call-template name="write.chunk">
1537
+ <xsl:with-param name="filename">
1538
+ <xsl:value-of select="$epub.cover.filename" />
1539
+ </xsl:with-param>
1540
+ <xsl:with-param name="method" select="'xml'" />
1541
+ <xsl:with-param name="encoding" select="'utf-8'" />
1542
+ <xsl:with-param name="indent" select="'no'" />
1543
+ <xsl:with-param name="quiet" select="$chunk.quietly" />
1544
+ <xsl:with-param name="content">
1545
+ <xsl:element namespace="http://www.w3.org/1999/xhtml" name="html">
1546
+ <xsl:element namespace="http://www.w3.org/1999/xhtml" name="head">
1547
+ <xsl:element namespace="http://www.w3.org/1999/xhtml" name="title">Cover</xsl:element>
1548
+ <xsl:element namespace="http://www.w3.org/1999/xhtml" name="style">
1549
+ <xsl:attribute name="type">text/css</xsl:attribute>
1550
+ <!-- Help the cover image scale nicely in the CSS then apply a max-width to look better in Adobe Digital Editions -->
1551
+ <xsl:text> img { max-width: 100%; }</xsl:text>
1552
+ </xsl:element>
1553
+ </xsl:element>
1554
+ <xsl:element namespace="http://www.w3.org/1999/xhtml" name="body">
1555
+ <xsl:element namespace="http://www.w3.org/1999/xhtml" name="div">
1556
+ <xsl:attribute name="id">
1557
+ <xsl:value-of select="$epub.cover.image.id"/>
1558
+ </xsl:attribute>
1559
+ <xsl:choose>
1560
+ <xsl:when test="d:imageobject[@role='front-large']">
1561
+ <xsl:apply-templates select="d:imageobject[@role='front-large']"/>
1562
+ </xsl:when>
1563
+ <xsl:otherwise>
1564
+ <xsl:apply-templates select="d:imageobject[1]"/>
1565
+ </xsl:otherwise>
1566
+ </xsl:choose>
1567
+ </xsl:element>
1568
+ <!-- If this is defined as an explicit cover page, then process
1569
+ any remaining text -->
1570
+ <xsl:if test="ancestor::d:cover">
1571
+ <xsl:apply-templates select="ancestor::d:cover/d:para"/>
1572
+ </xsl:if>
1573
+ </xsl:element>
1574
+ </xsl:element>
1575
+ </xsl:with-param>
1576
+ </xsl:call-template>
1577
+ </xsl:template>
1578
+
1579
+ <xsl:template name="cover-svg">
1580
+ <xsl:param name="node"/>
1581
+ </xsl:template>
1582
+
1583
+ <xsl:template name="toc-href">
1584
+ <xsl:param name="node" select="."/>
1585
+ <xsl:apply-templates select="$node" mode="recursive-chunk-filename">
1586
+ <xsl:with-param name="recursive" select="true()"/>
1587
+ </xsl:apply-templates>
1588
+ <xsl:text>-toc</xsl:text>
1589
+ <xsl:value-of select="$html.ext"/>
1590
+ </xsl:template>
1591
+
1592
+ <xsl:template match="d:bibliodiv[d:title]" mode="label.markup">
1593
+ </xsl:template>
1594
+
1595
+ <xsl:template match="d:token" mode="opf.manifest.font">
1596
+ <xsl:call-template name="embedded-font-item">
1597
+ <xsl:with-param name="font.file" select="."/>
1598
+ </xsl:call-template>
1599
+ </xsl:template>
1600
+
1601
+ <xsl:template name="embedded-font-item">
1602
+ <xsl:param name="font.file"/>
1603
+ <xsl:param name="font.order" select="1"/>
1604
+
1605
+ <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
1606
+ <xsl:attribute name="id">
1607
+ <xsl:value-of select="concat('epub.embedded.font.', $font.order)"/>
1608
+ </xsl:attribute>
1609
+ <xsl:attribute name="href"><xsl:value-of select="$font.file"/></xsl:attribute>
1610
+ <xsl:choose>
1611
+ <xsl:when test="contains($font.file, 'otf')">
1612
+ <xsl:attribute name="media-type">font/opentype</xsl:attribute>
1613
+ </xsl:when>
1614
+ <xsl:otherwise>
1615
+ <xsl:message>
1616
+ <xsl:text>WARNING: OpenType fonts should be supplied! (</xsl:text>
1617
+ <xsl:value-of select="$font.file"/>
1618
+ <xsl:text>)</xsl:text>
1619
+ </xsl:message>
1620
+ </xsl:otherwise>
1621
+ </xsl:choose>
1622
+ </xsl:element>
1623
+ </xsl:template>
1624
+
1625
+ <!-- Change section.heading to improve SEO on generated HTML by doing heading levels
1626
+ "correctly". SEO rules are sometimes silly silly, but this does actually create
1627
+ a semantic improvement.
1628
+ Note: This template needs to be manually maintained outside of the html/sections.xsl
1629
+ code, so make sure important changes get reintegrated. -->
1630
+ <xsl:template name="section.heading">
1631
+ <xsl:param name="section" select="."/>
1632
+ <xsl:param name="level" select="1"/>
1633
+ <xsl:param name="allow-anchors" select="1"/>
1634
+ <xsl:param name="title"/>
1635
+ <xsl:param name="class" select="'title'"/>
1636
+
1637
+ <xsl:variable name="id">
1638
+ <xsl:choose>
1639
+ <!-- Make sure the subtitle doesn't get the same id as the title -->
1640
+ <xsl:when test="self::d:subtitle">
1641
+ <xsl:call-template name="object.id">
1642
+ <xsl:with-param name="object" select="."/>
1643
+ </xsl:call-template>
1644
+ </xsl:when>
1645
+ <!-- if title is in an *info wrapper, get the grandparent -->
1646
+ <xsl:when test="contains(local-name(..), 'info')">
1647
+ <xsl:call-template name="object.id">
1648
+ <xsl:with-param name="object" select="../.."/>
1649
+ </xsl:call-template>
1650
+ </xsl:when>
1651
+ <xsl:otherwise>
1652
+ <xsl:call-template name="object.id">
1653
+ <xsl:with-param name="object" select=".."/>
1654
+ </xsl:call-template>
1655
+ </xsl:otherwise>
1656
+ </xsl:choose>
1657
+ </xsl:variable>
1658
+
1659
+ <!-- For SEO, we try to actually ensure we *always* output one and only one h1,
1660
+ so unlike the regular stylesheets, we don't add one to the section level and
1661
+ we get the right behavior because of chunking. -->
1662
+ <xsl:variable name="hlevel">
1663
+ <xsl:choose>
1664
+ <!-- highest valid HTML H level is H6; so anything nested deeper
1665
+ than 7 levels down just becomes H6 -->
1666
+ <xsl:when test="$level &gt; 6">6</xsl:when>
1667
+ <xsl:otherwise>
1668
+ <xsl:value-of select="$level"/>
1669
+ </xsl:otherwise>
1670
+ </xsl:choose>
1671
+ </xsl:variable>
1672
+ <xsl:element name="h{$hlevel}" namespace="http://www.w3.org/1999/xhtml">
1673
+ <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
1674
+ <xsl:if test="$css.decoration != '0'">
1675
+ <xsl:if test="$hlevel&lt;3">
1676
+ <xsl:attribute name="style">clear: both</xsl:attribute>
1677
+ </xsl:if>
1678
+ </xsl:if>
1679
+ <xsl:if test="$allow-anchors != 0 and $generate.id.attributes = 0">
1680
+ <xsl:call-template name="anchor">
1681
+ <xsl:with-param name="node" select="$section"/>
1682
+ <xsl:with-param name="conditional" select="0"/>
1683
+ </xsl:call-template>
1684
+ </xsl:if>
1685
+ <xsl:if test="$generate.id.attributes != 0 and not(local-name(.) = 'appendix')">
1686
+ <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
1687
+ </xsl:if>
1688
+ <xsl:copy-of select="$title"/>
1689
+ </xsl:element>
1690
+ </xsl:template>
1691
+
1692
+ <!-- ==================================================================== -->
1693
+
1694
+ <xsl:template match="d:bridgehead">
1695
+ <xsl:variable name="container" select="(ancestor::d:appendix |ancestor::d:article |ancestor::d:bibliography |ancestor::d:chapter |ancestor::d:glossary |ancestor::d:glossdiv |ancestor::d:index |ancestor::d:partintro |ancestor::d:preface |ancestor::d:refsect1 |ancestor::d:refsect2 |ancestor::d:refsect3 |ancestor::d:sect1 |ancestor::d:sect2 |ancestor::d:sect3 |ancestor::d:sect4 |ancestor::d:sect5 |ancestor::d:section |ancestor::d:setindex |ancestor::d:simplesect)[last()]"/>
1696
+
1697
+ <xsl:variable name="clevel">
1698
+ <xsl:choose>
1699
+ <xsl:when test="local-name($container) = 'appendix' or local-name($container) = 'chapter' or local-name($container) = 'article' or local-name($container) = 'bibliography' or local-name($container) = 'glossary' or local-name($container) = 'index' or local-name($container) = 'partintro' or local-name($container) = 'preface' or local-name($container) = 'setindex'">1</xsl:when>
1700
+ <xsl:when test="local-name($container) = 'glossdiv'">
1701
+ <xsl:value-of select="count(ancestor::d:glossdiv)+1"/>
1702
+ </xsl:when>
1703
+ <xsl:when test="local-name($container) = 'sect1' or local-name($container) = 'sect2' or local-name($container) = 'sect3' or local-name($container) = 'sect4' or local-name($container) = 'sect5' or local-name($container) = 'refsect1' or local-name($container) = 'refsect2' or local-name($container) = 'refsect3' or local-name($container) = 'section' or local-name($container) = 'simplesect'">
1704
+ <xsl:variable name="slevel">
1705
+ <xsl:call-template name="section.level">
1706
+ <xsl:with-param name="node" select="$container"/>
1707
+ </xsl:call-template>
1708
+ </xsl:variable>
1709
+ <xsl:value-of select="$slevel + 1"/>
1710
+ </xsl:when>
1711
+ <xsl:otherwise>1</xsl:otherwise>
1712
+ </xsl:choose>
1713
+ </xsl:variable>
1714
+
1715
+ <!-- HTML H level is one higher than section level -->
1716
+ <xsl:variable name="hlevel">
1717
+ <xsl:choose>
1718
+ <xsl:when test="@renderas = 'sect1'">1</xsl:when>
1719
+ <xsl:when test="@renderas = 'sect2'">2</xsl:when>
1720
+ <xsl:when test="@renderas = 'sect3'">3</xsl:when>
1721
+ <xsl:when test="@renderas = 'sect4'">4</xsl:when>
1722
+ <xsl:when test="@renderas = 'sect5'">5</xsl:when>
1723
+ <xsl:otherwise>
1724
+ <xsl:value-of select="$clevel + 1"/>
1725
+ </xsl:otherwise>
1726
+ </xsl:choose>
1727
+ </xsl:variable>
1728
+
1729
+ <xsl:element name="h{$hlevel}" namespace="http://www.w3.org/1999/xhtml">
1730
+ <xsl:call-template name="anchor">
1731
+ <xsl:with-param name="conditional" select="0"/>
1732
+ </xsl:call-template>
1733
+ <xsl:apply-templates/>
1734
+ </xsl:element>
1735
+ </xsl:template>
1736
+
1737
+ <!-- SEO customization #2 -->
1738
+ <xsl:template name="component.title">
1739
+ <xsl:param name="node" select="."/>
1740
+
1741
+ <xsl:variable name="level">
1742
+ <xsl:choose>
1743
+ <xsl:when test="ancestor::d:section">
1744
+ <xsl:value-of select="count(ancestor::d:section)+1"/>
1745
+ </xsl:when>
1746
+ <xsl:when test="ancestor::d:sect5">6</xsl:when>
1747
+ <xsl:when test="ancestor::d:sect4">5</xsl:when>
1748
+ <xsl:when test="ancestor::d:sect3">4</xsl:when>
1749
+ <xsl:when test="ancestor::d:sect2">3</xsl:when>
1750
+ <xsl:when test="ancestor::d:sect1">2</xsl:when>
1751
+ <xsl:otherwise>1</xsl:otherwise>
1752
+ </xsl:choose>
1753
+ </xsl:variable>
1754
+
1755
+ <xsl:element name="h{$level}" namespace="http://www.w3.org/1999/xhtml">
1756
+ <xsl:attribute name="class">title</xsl:attribute>
1757
+ <xsl:if test="$generate.id.attributes = 0">
1758
+ <xsl:call-template name="anchor">
1759
+ <xsl:with-param name="node" select="$node"/>
1760
+ <xsl:with-param name="conditional" select="0"/>
1761
+ </xsl:call-template>
1762
+ </xsl:if>
1763
+ <xsl:apply-templates select="$node" mode="object.title.markup">
1764
+ <xsl:with-param name="allow-anchors" select="1"/>
1765
+ </xsl:apply-templates>
1766
+ </xsl:element>
1767
+ </xsl:template>
1768
+
1769
+ </xsl:stylesheet>