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"
17 extension-element-prefixes="date stext xtext"
18 exclude-result-prefixes="exsl date db dc h ncx ng opf stext str xtext d"
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" />
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">
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 -->
38 <xsl:param name="manifest.in.base.dir" select="'1'"/>
39 <xsl:param name="base.dir" select="''"/>
40 <!-- epub.oebps.dir must be the html path relative to base.dir -->
41 <xsl:param name="epub.oebps.dir" select="'OEBPS/'"/>
42 <!-- This version has no trailing slash -->
43 <xsl:variable name="clean.oebps.dir">
45 <xsl:when test="substring($epub.oebps.dir,
46 string-length($epub.oebps.dir), 1) = '/'">
47 <xsl:value-of select="substring($epub.oebps.dir, 1,
48 string-length($epub.oebps.dir) - 1)"/>
51 <xsl:value-of select="$epub.oebps.dir"/>
57 <!-- HTML chunk output goes to $base.dir/OEPBS -->
58 <xsl:variable name="chunk.base.dir">
60 <xsl:when test="$base.dir != '' and contains($base.dir, $clean.oebps.dir)">
61 <xsl:value-of select="substring-before($base.dir, $clean.oebps.dir)"/>
63 <!-- If epub.oebps.dir reset but base.dir still has OEBPS: -->
64 <xsl:when test="$base.dir != '' and contains($base.dir, 'OEBPS')">
65 <xsl:value-of select="substring-before($base.dir, 'OEBPS')"/>
67 <xsl:when test="string-length($base.dir) = 0"></xsl:when>
68 <!-- make sure to add trailing slash if omitted by user -->
69 <xsl:when test="substring($base.dir, string-length($base.dir), 1) = '/'">
70 <xsl:value-of select="$base.dir"/>
73 <xsl:value-of select="concat($base.dir, '/')"/>
76 <xsl:value-of select="$clean.oebps.dir"/>
77 <xsl:text>/</xsl:text>
80 <!-- This param only has a side effect of checking for base.dir usage -->
82 <xsl:param name="epub.ncx.filename" select="'toc.ncx'"/>
83 <xsl:param name="epub.package.filename" select="'content.opf'"/>
84 <xsl:param name="epub.container.filename" select="'container.xml'"/>
85 <xsl:param name="epub.opf.filename">
86 <xsl:value-of select="$clean.oebps.dir"/>
87 <xsl:text>/</xsl:text>
88 <xsl:value-of select="$epub.package.filename"/>
90 <xsl:param name="epub.cover.filename" select="concat($chunk.base.dir, 'cover', $html.ext)"/>
91 <xsl:param name="epub.cover.id" select="'cover'"/>
92 <xsl:param name="epub.cover.html" select="'cover.html'" />
93 <xsl:param name="epub.cover.image.id" select="'cover-image'"/>
94 <xsl:param name="epub.cover.linear" select="0" />
95 <xsl:param name="epub.ncx.toc.id">ncxtoc</xsl:param>
96 <xsl:param name="epub.html.toc.id">htmltoc</xsl:param>
97 <xsl:variable name="epub.metainf.dir" select="concat($chunk.base.dir, '../META-INF/')"/>
99 <xsl:param name="epub.embedded.fonts"></xsl:param>
101 <!-- Turning this on crashes ADE, which is unbelievably awesome -->
102 <xsl:param name="formal.object.break.after">0</xsl:param>
105 <!-- Per Bob Stayton:
106 """Process your documents with the css.decoration parameter set to zero.
107 That will avoid the use of style attributes in XHTML elements where they are not permitted."""
108 http://www.sagehill.net/docbookxsl/OtherOutputForms.html#StrictXhtmlValid -->
109 <xsl:param name="css.decoration" select="0"/>
110 <xsl:param name="custom.css.source"></xsl:param> <!-- FIXME: Align with current CSS parameter design -->
112 <xsl:param name="callout.graphics" select="1"/>
113 <xsl:param name="callout.graphics.extension">.png</xsl:param>
114 <xsl:param name="callout.graphics.number.limit" select="15"/>
115 <xsl:param name="callout.graphics.path" select="'images/callouts/'"/>
117 <!-- no navigation in .epub -->
118 <xsl:param name="suppress.navigation" select="'1'"/>
120 <xsl:variable name="toc.params">
121 <xsl:call-template name="find.path.params">
122 <xsl:with-param name="node" select="/*"/>
123 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
126 <xsl:variable name="root.is.a.chunk">
128 <xsl:when test="/*[not(self::d:book)][not(d:sect1) or not(d:section)]">
129 <xsl:text>1</xsl:text>
131 <xsl:when test="/d:book[*[last()][self::d:bookinfo]]|d:book[d:bookinfo]">
132 <xsl:text>1</xsl:text>
134 <xsl:when test="/d:book[*[last()][self::d:info]]|d:book[d:info]">
135 <xsl:text>1</xsl:text>
137 <xsl:when test="/d:bibliography">
138 <xsl:text>1</xsl:text>
141 <xsl:text>0</xsl:text>
146 <xsl:key name="image-filerefs" match="d:graphic|d:inlinegraphic|d:imagedata" use="@fileref"/>
148 <xsl:template match="/" priority="1">
149 <!-- * Get a title for current doc so that we let the user -->
150 <!-- * know what document we are processing at this point. -->
151 <xsl:variable name="doc.title">
152 <xsl:call-template name="get.doc.title" />
155 <!-- fix namespace if necessary -->
156 <xsl:when test="$exsl.node.set.available != 0 and
157 namespace-uri(/*) != 'http://docbook.org/ns/docbook'">
158 <xsl:call-template name="log.message">
159 <xsl:with-param name="level">Note</xsl:with-param>
160 <xsl:with-param name="source" select="$doc.title"/>
161 <xsl:with-param name="context-desc">
162 <xsl:text>namesp. add</xsl:text>
164 <xsl:with-param name="message">
165 <xsl:text>added namespace before processing</xsl:text>
168 <!-- DEBUG: uncomment to save namespace-fixed document.
169 <xsl:message>Saving namespace-fixed document.</xsl:message>
170 <xsl:call-template name="write.chunk">
171 <xsl:with-param name="filename" select="'namespace-fixed.debug.xml'"/>
172 <xsl:with-param name="method" select="'xml'"/>
173 <xsl:with-param name="content">
174 <xsl:copy-of select="exsl:node-set($with.namespace)"/>
178 <xsl:apply-templates select="exsl:node-set($with.namespace)"/>
180 <!-- Can't process unless namespace fixed with exsl node-set()-->
181 <xsl:when test="namespace-uri(/*) != 'http://docbook.org/ns/docbook'">
182 <xsl:message terminate="yes">
183 <xsl:text>Unable to add the namespace from DB4 document,</xsl:text>
184 <xsl:text> cannot proceed.</xsl:text>
189 <xsl:when test="$rootid != ''">
192 test="count(key('id',$rootid)) = 0">
193 <xsl:message terminate="yes">
194 <xsl:text>ID '</xsl:text>
195 <xsl:value-of select="$rootid" />
196 <xsl:text>' not found in document.</xsl:text>
201 test="$collect.xref.targets = 'yes' or
202 $collect.xref.targets = 'only'">
204 select="key('id', $rootid)" mode="collect.targets" />
207 test="$collect.xref.targets != 'only'">
210 <xsl:value-of select="$rootid" />
213 select="key('id',$rootid)" mode="process.root" />
214 <xsl:call-template name="ncx" />
221 test="$collect.xref.targets = 'yes' or
222 $collect.xref.targets = 'only'">
223 <xsl:apply-templates select="/"
224 mode="collect.targets" />
227 test="$collect.xref.targets != 'only'">
228 <xsl:apply-templates select="/"
229 mode="process.root" />
230 <xsl:call-template name="ncx" />
231 <xsl:call-template name="opf" />
232 <xsl:call-template name="cover" />
233 <xsl:call-template name="container" />
241 <xsl:template name="package-identifier">
242 <xsl:variable name="info" select="*/*[contains(local-name(.), 'info')][1]"/>
245 <xsl:when test="$info/d:biblioid">
246 <xsl:if test="$info/d:biblioid[1][@class = 'doi' or
250 <xsl:text>urn:</xsl:text>
251 <xsl:value-of select="$info/d:biblioid[1]/@class"/>
252 <xsl:text>:</xsl:text>
254 <xsl:value-of select="$info/d:biblioid[1]"/>
256 <xsl:when test="$info/d:isbn">
257 <xsl:text>urn:isbn:</xsl:text>
258 <xsl:value-of select="$info/d:isbn[1]"/>
260 <xsl:when test="$info/d:issn">
261 <xsl:text>urn:issn:</xsl:text>
262 <xsl:value-of select="$info/d:issn[1]"/>
266 <xsl:when test="$info/d:invpartnumber">
267 <xsl:value-of select="$info/d:invpartnumber[1]"/>
269 <xsl:when test="$info/d:issuenum">
270 <xsl:value-of select="$info[1]/d:issuenum[1]"/>
272 <xsl:when test="$info/d:productnumber">
273 <xsl:value-of select="$info[1]/d:productnumber[1]"/>
275 <xsl:when test="$info/d:seriesvolnums">
276 <xsl:value-of select="$info[1]/d:seriesvolnums[1]"/>
278 <xsl:when test="$info/d:volumenum">
279 <xsl:value-of select="$info[1]/d:volumenum[1]"/>
282 <xsl:when test="$info/d:pubsnumber">
283 <xsl:value-of select="$info[1]/d:pubsnumber[1]"/>
286 <xsl:text>_</xsl:text>
288 <xsl:when test="@id">
289 <xsl:value-of select="@id"/>
291 <xsl:when test="@xml:id">
292 <xsl:value-of select="@xml:id"/>
295 <!-- TODO: Do UUIDs here -->
296 <xsl:value-of select="generate-id(.)"/>
304 <xsl:template name="opf">
305 <xsl:variable name="package-identifier-id"><xsl:value-of select="concat(name(/*), 'id')"/></xsl:variable>
306 <xsl:variable name="doc.title">
307 <xsl:call-template name="get.doc.title" />
309 <xsl:call-template name="write.chunk">
310 <xsl:with-param name="filename">
311 <xsl:value-of select="$chunk.base.dir"/>
312 <xsl:text>../</xsl:text>
313 <xsl:value-of select="$epub.opf.filename" />
315 <xsl:with-param name="method" select="'xml'" />
316 <xsl:with-param name="encoding" select="'utf-8'" />
317 <xsl:with-param name="indent" select="'no'" />
318 <xsl:with-param name="quiet" select="$chunk.quietly" />
319 <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
320 <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
321 <xsl:with-param name="content">
322 <xsl:element namespace="http://www.idpf.org/2007/opf" name="package">
323 <xsl:attribute name="version">2.0</xsl:attribute>
324 <xsl:attribute name="unique-identifier"> <xsl:value-of select="$package-identifier-id"/> </xsl:attribute>
326 <xsl:element namespace="http://www.idpf.org/2007/opf" name="metadata">
327 <xsl:element name="dc:identifier">
328 <xsl:attribute name="id"><xsl:value-of select="$package-identifier-id"/></xsl:attribute>
329 <xsl:call-template name="package-identifier"/>
332 <xsl:element name="dc:title">
333 <xsl:value-of select="normalize-space($doc.title)"/>
336 <xsl:apply-templates select="/*/*[contains(name(.), 'info')]/*"
337 mode="opf.metadata"/>
338 <xsl:element name="dc:language">
339 <xsl:call-template name="l10n.language">
340 <xsl:with-param name="target" select="/*"/>
344 <xsl:if test="/*/*[d:cover or contains(name(.), 'info')]//d:mediaobject[@role='cover' or ancestor::d:cover]">
345 <xsl:element namespace="http://www.idpf.org/2007/opf" name="meta">
346 <xsl:attribute name="name">cover</xsl:attribute>
347 <xsl:attribute name="content">
348 <xsl:value-of select="$epub.cover.image.id"/>
354 <xsl:call-template name="opf.manifest"/>
355 <xsl:call-template name="opf.spine"/>
356 <xsl:call-template name="opf.guide"/>
363 <xsl:template name="container">
364 <xsl:call-template name="write.chunk">
365 <xsl:with-param name="filename">
366 <xsl:value-of select="concat($epub.metainf.dir, $epub.container.filename)" />
368 <xsl:with-param name="method" select="'xml'" />
369 <xsl:with-param name="encoding" select="'utf-8'" />
370 <xsl:with-param name="indent" select="'no'" />
371 <xsl:with-param name="quiet" select="$chunk.quietly" />
372 <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
373 <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
375 <xsl:with-param name="content">
376 <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="container">
377 <xsl:attribute name="version">1.0</xsl:attribute>
378 <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="rootfiles">
379 <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="rootfile">
380 <xsl:attribute name="full-path">
381 <xsl:value-of select="$epub.opf.filename" />
383 <xsl:attribute name="media-type">
384 <xsl:text>application/oebps-package+xml</xsl:text>
393 <xsl:template name="ncx">
394 <xsl:call-template name="write.chunk">
395 <xsl:with-param name="filename">
396 <xsl:if test="$manifest.in.base.dir != 0">
397 <xsl:value-of select="$chunk.base.dir" />
399 <xsl:value-of select="$epub.ncx.filename" />
401 <xsl:with-param name="method" select="'xml'" />
402 <xsl:with-param name="encoding" select="'utf-8'" />
403 <xsl:with-param name="indent" select="'no'" />
404 <xsl:with-param name="quiet" select="$chunk.quietly" />
405 <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
406 <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
407 <xsl:with-param name="content">
408 <xsl:element name="ncx" namespace="http://www.daisy.org/z3986/2005/ncx/">
409 <xsl:attribute name="version">2005-1</xsl:attribute>
411 <!-- Via Martin Goerner: On covers: the IDPF2.0 standard unfortunately does not have a provision for
412 covers. We had to add one and we did so in conjunction with the IDPF and
413 various publishers. The tag chosen to define the covers is:
414 <meta name="cover" content="-reference to a manifest item-">
415 Then, we also added a bit of logic to get rid cleanly of the HTML cover
416 people usually add because the logical cover is not specced by the IDPF. So,
417 if the HTML cover item is marked linear="no" AND there is a guide item of
418 type="cover" pointing to it AND there is a logical cover specified in a
419 <meta name="cover"> tag, THEN, the HTML cover is discarded. -->
420 <xsl:element name="head" namespace="http://www.daisy.org/z3986/2005/ncx/">
421 <xsl:if test="/*/*[d:cover or contains(name(.), 'info')]//d:mediaobject[@role='cover' or ancestor::d:cover]">
422 <xsl:element name="meta" namespace="http://www.daisy.org/z3986/2005/ncx/">
423 <xsl:attribute name="name">cover</xsl:attribute>
424 <xsl:attribute name="content">
425 <xsl:value-of select="$epub.cover.id"/>
429 <xsl:element name="meta" namespace="http://www.daisy.org/z3986/2005/ncx/">
430 <xsl:attribute name="name">dtb:uid</xsl:attribute>
431 <xsl:attribute name="content"><xsl:call-template name="package-identifier"/></xsl:attribute>
436 <xsl:when test="$rootid != ''">
437 <xsl:variable name="title">
438 <xsl:if test="$epub.autolabel != 0">
439 <xsl:variable name="label.markup">
440 <xsl:apply-templates select="key('id',$rootid)" mode="label.markup" />
442 <xsl:if test="normalize-space($label.markup)">
443 <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
446 <xsl:apply-templates select="key('id',$rootid)" mode="title.markup" />
448 <xsl:variable name="href">
449 <xsl:call-template name="href.target.with.base.dir">
450 <xsl:with-param name="object" select="key('id',$rootid)" />
453 <xsl:element name="docTitle" namespace="http://www.daisy.org/z3986/2005/ncx/">
454 <xsl:element name="text" namespace="http://www.daisy.org/z3986/2005/ncx/"><xsl:value-of select="normalize-space($title)" /> </xsl:element>
456 <xsl:element name="navMap" namespace="http://www.daisy.org/z3986/2005/ncx/">
457 <xsl:apply-templates select="key('id',$rootid)/*" mode="ncx" />
461 <xsl:variable name="title">
462 <xsl:if test="$epub.autolabel != 0">
463 <xsl:variable name="label.markup">
464 <xsl:apply-templates select="/*" mode="label.markup" />
466 <xsl:if test="normalize-space($label.markup)">
467 <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
470 <xsl:apply-templates select="/*" mode="title.markup" />
472 <xsl:variable name="href">
473 <xsl:call-template name="href.target.with.base.dir">
474 <xsl:with-param name="object" select="/" />
477 <xsl:element name="docTitle" namespace="http://www.daisy.org/z3986/2005/ncx/">
478 <xsl:element name="text" namespace="http://www.daisy.org/z3986/2005/ncx/">
479 <xsl:value-of select="normalize-space($title)" />
482 <xsl:element name="navMap" namespace="http://www.daisy.org/z3986/2005/ncx/">
484 <xsl:when test="$root.is.a.chunk != '0'">
485 <xsl:apply-templates select="/*" mode="ncx" />
488 <xsl:apply-templates select="/*/*" mode="ncx" />
500 <xsl:template match="d:book|
517 d:bibliodiv[d:title]|
521 <xsl:variable name="depth" select="count(ancestor::*)"/>
522 <xsl:variable name="title">
523 <xsl:if test="$epub.autolabel != 0">
524 <xsl:variable name="label.markup">
525 <xsl:apply-templates select="." mode="label.markup" />
527 <xsl:if test="normalize-space($label.markup)">
529 select="concat($label.markup,$autotoc.label.separator)" />
532 <xsl:apply-templates select="." mode="title.markup" />
535 <xsl:variable name="href">
536 <xsl:call-template name="href.target.with.base.dir">
537 <xsl:with-param name="context" select="/" />
538 <!-- Generate links relative to the location of root file/toc.xml file -->
542 <xsl:variable name="id">
543 <xsl:value-of select="generate-id(.)"/>
545 <xsl:variable name="order">
546 <xsl:value-of select="$depth +
547 count(preceding::d:part|
548 preceding::d:reference|
549 preceding::d:book[parent::d:set]|
550 preceding::d:preface|
551 preceding::d:chapter|
552 preceding::d:bibliography|
553 preceding::d:appendix|
554 preceding::d:article|
555 preceding::d:glossary|
556 preceding::d:section[not(parent::d:partintro)]|
557 preceding::d:sect1[not(parent::d:partintro)]|
558 preceding::d:sect2[not(ancestor::d:partintro)]|
559 preceding::d:sect3[not(ancestor::d:partintro)]|
560 preceding::d:sect4[not(ancestor::d:partintro)]|
561 preceding::d:sect5[not(ancestor::d:partintro)]|
562 preceding::d:refentry|
563 preceding::d:colophon|
564 preceding::d:bibliodiv[d:title]|
565 preceding::d:index)"/>
568 <xsl:element name="navPoint" namespace="http://www.daisy.org/z3986/2005/ncx/">
569 <xsl:attribute name="id">
570 <xsl:value-of select="$id"/>
573 <xsl:attribute name="playOrder">
575 <xsl:when test="/*[self::d:set]">
576 <xsl:value-of select="$order"/>
578 <xsl:when test="$root.is.a.chunk != '0'">
579 <xsl:value-of select="$order + 1"/>
582 <xsl:value-of select="$order - 0"/>
586 <xsl:element name="navLabel" namespace="http://www.daisy.org/z3986/2005/ncx/">
587 <xsl:element name="text" namespace="http://www.daisy.org/z3986/2005/ncx/"><xsl:value-of select="normalize-space($title)"/> </xsl:element>
589 <xsl:element name="content" namespace="http://www.daisy.org/z3986/2005/ncx/">
590 <xsl:attribute name="src">
591 <xsl:value-of select="$href"/>
594 <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"/>
599 <xsl:template match="*" mode="opf.metadata">
600 <!-- override if you care -->
603 <xsl:template match="d:authorgroup" mode="opf.metadata">
604 <xsl:apply-templates select="d:author|d:corpauthor" mode="opf.metadata"/>
607 <xsl:template match="d:author|d:corpauthor" mode="opf.metadata">
608 <xsl:variable name="n">
609 <xsl:call-template name="person.name">
610 <xsl:with-param name="node" select="."/>
613 <xsl:element name="dc:creator">
614 <xsl:attribute name="opf:file-as">
615 <xsl:variable name="attvalue">
616 <xsl:call-template name="person.name.last-first">
617 <xsl:with-param name="node" select="."/>
620 <xsl:value-of select="$attvalue"/>
622 <xsl:value-of select="normalize-space(string($n))"/>
626 <xsl:template match="d:date" mode="opf.metadata">
627 <xsl:element name="dc:date">
629 <xsl:when test="processing-instruction('dbtimestamp')">
630 <xsl:call-template name="datetime.format">
631 <xsl:with-param name="date">
633 <xsl:when test="function-available('date:date-time')">
634 <xsl:value-of select="date:date-time()"/>
636 <xsl:when test="function-available('date:dateTime')">
638 <xsl:value-of select="date:dateTime()"/>
642 <!-- We need an ISO date -->
643 <xsl:with-param name="format">Y-m-d</xsl:with-param>
647 <xsl:value-of select="normalize-space(string(.))"/>
654 <!-- Space separate the compontents of the abstract (dropping the inline markup, sadly) -->
655 <xsl:template match="d:abstract" mode="opf.metadata">
656 <xsl:element name="dc:description">
657 <xsl:for-each select="d:formalpara|d:para|d:simpara|d:title">
659 <xsl:when test="self::d:formalpara">
660 <xsl:value-of select="normalize-space(string(d:title))"/>
661 <xsl:text>: </xsl:text>
662 <xsl:value-of select="normalize-space(string(d:para))"/>
665 <xsl:value-of select="normalize-space(string(.))"/>
668 <xsl:if test="self::d:title">
669 <xsl:text>:</xsl:text>
671 <xsl:if test="not(position() = last())">
672 <xsl:text> </xsl:text>
678 <xsl:template match="d:subjectset" mode="opf.metadata">
679 <xsl:apply-templates select="d:subject/d:subjectterm" mode="opf.metadata"/>
682 <xsl:template match="d:subjectterm" mode="opf.metadata">
683 <xsl:element name="dc:subject">
684 <xsl:value-of select="normalize-space(string(.))"/>
688 <xsl:template match="d:publisher" mode="opf.metadata">
689 <xsl:apply-templates select="d:publishername" mode="opf.metadata"/>
692 <xsl:template match="d:publishername" mode="opf.metadata">
693 <xsl:element name="dc:publisher">
694 <xsl:value-of select="normalize-space(string(.))"/>
698 <xsl:template match="d:copyright" mode="opf.metadata">
699 <xsl:variable name="copyright.date">
700 <xsl:call-template name="copyright.years">
701 <xsl:with-param name="years" select="d:year"/>
702 <xsl:with-param name="print.ranges" select="$make.year.ranges"/>
703 <xsl:with-param name="single.year.ranges" select="$make.single.year.ranges"/>
706 <xsl:if test="not(../d:date)">
707 <xsl:element name="dc:date">
708 <xsl:call-template name="copyright.years">
709 <xsl:with-param name="years" select="d:year[last()]"/>
710 <xsl:with-param name="print.ranges" select="0"/>
711 <xsl:with-param name="single.year.ranges" select="0"/>
715 <xsl:element name="dc:rights">
716 <xsl:call-template name="gentext">
717 <xsl:with-param name="key" select="'Copyright'"/>
719 <xsl:call-template name="gentext.space"/>
720 <xsl:text>©</xsl:text>
721 <xsl:call-template name="gentext.space"/>
722 <xsl:value-of select="$copyright.date"/>
723 <xsl:call-template name="gentext.space"/>
724 <xsl:apply-templates select="d:holder" mode="titlepage.mode"/>
728 <xsl:template name="opf.guide">
729 <xsl:variable name="info" select="*/*[contains(local-name(.), 'info')][1]"/>
731 <xsl:if test="contains($toc.params, 'toc') or
733 $info//d:mediaobject[@role='cover' or ancestor::d:cover]">
734 <xsl:element namespace="http://www.idpf.org/2007/opf" name="guide">
735 <xsl:if test="$info/d:cover or $info//d:mediaobject[@role='cover' or ancestor::d:cover]">
736 <xsl:element namespace="http://www.idpf.org/2007/opf" name="reference">
737 <xsl:attribute name="href">
738 <xsl:value-of select="$epub.cover.html" />
740 <xsl:attribute name="type">cover</xsl:attribute>
741 <xsl:attribute name="title">Cover</xsl:attribute>
745 <xsl:if test="contains($toc.params, 'toc')">
746 <xsl:element namespace="http://www.idpf.org/2007/opf" name="reference">
747 <xsl:attribute name="href">
748 <xsl:call-template name="toc-href">
749 <xsl:with-param name="node" select="/*"/>
752 <xsl:attribute name="type">toc</xsl:attribute>
753 <xsl:attribute name="title">Table of Contents</xsl:attribute>
760 <xsl:template name="opf.spine">
761 <xsl:variable name="info" select="*/*[contains(local-name(.), 'info')][1]"/>
762 <xsl:element namespace="http://www.idpf.org/2007/opf" name="spine">
763 <xsl:attribute name="toc">
764 <xsl:value-of select="$epub.ncx.toc.id"/>
767 <xsl:call-template name="spine.cover"/>
769 <xsl:if test="contains($toc.params, 'toc')">
770 <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
771 <xsl:attribute name="idref"> <xsl:value-of select="$epub.html.toc.id"/> </xsl:attribute>
772 <xsl:attribute name="linear">yes</xsl:attribute>
776 <!-- TODO: be nice to have a idref="titlepage" here -->
778 <xsl:when test="$root.is.a.chunk != '0'">
779 <xsl:apply-templates select="/*" mode="opf.spine"/>
782 <xsl:apply-templates select="/*/*" mode="opf.spine"/>
788 <xsl:template name="spine.cover">
789 <xsl:variable name="info" select="*/*[contains(local-name(.), 'info')][1]"/>
790 <xsl:variable name="cover.image"
791 select="$info//d:mediaobject[@role='cover' or ancestor::d:cover]"/>
793 <xsl:if test="$cover.image">
794 <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
795 <xsl:attribute name="idref">
796 <xsl:value-of select="$epub.cover.id"/>
798 <xsl:attribute name="linear">
800 <xsl:when test="$epub.cover.linear">
801 <xsl:text>yes</xsl:text>
803 <xsl:otherwise>no</xsl:otherwise>
811 <xsl:template match="*" mode="opf.spine">
812 <xsl:variable name="is.chunk">
813 <xsl:call-template name="chunk">
814 <xsl:with-param name="node" select="."/>
818 <xsl:if test="$is.chunk != 0">
819 <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
820 <xsl:attribute name="idref">
821 <xsl:value-of select="generate-id(.)"/>
824 <xsl:apply-templates select="*" mode="opf.spine"/>
828 <xsl:template name="opf.manifest">
829 <xsl:element namespace="http://www.idpf.org/2007/opf" name="manifest">
830 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
831 <xsl:attribute name="id"> <xsl:value-of select="$epub.ncx.toc.id"/> </xsl:attribute>
832 <xsl:attribute name="media-type">application/x-dtbncx+xml</xsl:attribute>
833 <xsl:attribute name="href"><xsl:value-of select="$epub.ncx.filename"/> </xsl:attribute>
836 <xsl:if test="contains($toc.params, 'toc')">
837 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
838 <xsl:attribute name="id"> <xsl:value-of select="$epub.html.toc.id"/> </xsl:attribute>
839 <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
840 <xsl:attribute name="href">
841 <xsl:call-template name="toc-href">
842 <xsl:with-param name="node" select="/*"/>
848 <xsl:if test="$html.stylesheet != ''">
849 <xsl:call-template name="css.item">
850 <xsl:with-param name="stylesheets" select="$html.stylesheet"/>
854 <xsl:if test="/*/*[d:cover or contains(name(.), 'info')]//d:mediaobject[@role='cover' or ancestor::d:cover]">
855 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
856 <xsl:attribute name="id"> <xsl:value-of select="$epub.cover.id"/> </xsl:attribute>
857 <xsl:attribute name="href">
858 <xsl:value-of select="$epub.cover.html"/>
860 <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
865 <xsl:when test="$epub.embedded.fonts != '' and not(contains($epub.embedded.fonts, ','))">
866 <xsl:call-template name="embedded-font-item">
867 <xsl:with-param name="font.file" select="$epub.embedded.fonts"/> <!-- There is just one -->
870 <xsl:when test="$epub.embedded.fonts != ''">
871 <xsl:variable name="font.file.tokens" select="str:tokenize($epub.embedded.fonts, ',')"/>
872 <xsl:for-each select="exsl:node-set($font.file.tokens)">
873 <xsl:call-template name="embedded-font-item">
874 <xsl:with-param name="font.file" select="."/>
875 <xsl:with-param name="font.order" select="position()"/>
881 <!-- TODO: be nice to have a id="titlepage" here -->
882 <xsl:apply-templates select="//d:part|
883 //d:book[*[last()][self::d:bookinfo]]|
884 //d:book[d:bookinfo]|
885 //d:book[*[last()][self::d:info]]|
904 //d:bibliodiv[d:title]|
911 //d:inlinemediaobject"
912 mode="opf.manifest"/>
913 <xsl:call-template name="opf.calloutlist"/>
917 <xsl:template name="opf.calloutlist">
918 <xsl:variable name="format">
919 <xsl:call-template name="guess-media-type">
920 <xsl:with-param name="ext" select="$callout.graphics.extension"/>
923 <xsl:if test="$callout.graphics != 0 and (//d:calloutlist|//d:co)">
924 <xsl:call-template name="opf.reference.callout">
925 <xsl:with-param name="conum" select="1"/>
926 <xsl:with-param name="format" select="$format"/>
931 <xsl:template name="opf.reference.callout">
932 <xsl:param name="conum"/>
933 <xsl:param name="format"/>
935 <xsl:variable name="filename" select="concat($callout.graphics.path, $conum, $callout.graphics.extension)"/>
937 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
938 <xsl:attribute name="id"> <xsl:value-of select="concat(generate-id(.), 'callout', $conum)"/> </xsl:attribute>
939 <xsl:attribute name="href"> <xsl:value-of select="$filename"/> </xsl:attribute>
940 <xsl:attribute name="media-type">
941 <xsl:value-of select="$format"/>
944 <xsl:if test="($conum < $callout.graphics.number.limit)">
945 <xsl:call-template name="opf.reference.callout">
946 <xsl:with-param name="conum" select="$conum + 1"/>
947 <xsl:with-param name="format" select="$format"/>
952 <xsl:template name="guess-media-type">
953 <xsl:param name="ext"></xsl:param>
955 <xsl:when test="contains($ext, '.gif')">
956 <xsl:text>image/gif</xsl:text>
958 <xsl:when test="contains($ext, 'GIF')">
959 <xsl:text>image/gif</xsl:text>
961 <xsl:when test="contains($ext, '.png')">
962 <xsl:text>image/png</xsl:text>
964 <xsl:when test="contains($ext, 'PNG')">
965 <xsl:text>image/png</xsl:text>
967 <xsl:when test="contains($ext, '.jpeg')">
968 <xsl:text>image/jpeg</xsl:text>
970 <xsl:when test="contains($ext, 'JPEG')">
971 <xsl:text>image/jpeg</xsl:text>
973 <xsl:when test="contains($ext, '.jpg')">
974 <xsl:text>image/jpeg</xsl:text>
976 <xsl:when test="contains($ext, 'JPG')">
977 <xsl:text>image/jpeg</xsl:text>
979 <xsl:when test="contains($ext, '.svg')">
980 <xsl:text>image/svg+xml</xsl:text>
982 <xsl:when test="contains($ext, 'SVG')">
983 <xsl:text>image/svg+xml</xsl:text>
987 <xsl:text></xsl:text>
992 <xsl:template match="d:mediaobject|
997 <xsl:variable name="olist" select="d:imageobject|d:imageobjectco |d:videoobject|d:audioobject |d:textobject"/>
999 <xsl:variable name="object.index">
1000 <xsl:call-template name="select.mediaobject.index">
1001 <xsl:with-param name="olist" select="$olist"/>
1002 <xsl:with-param name="count" select="1"/>
1003 </xsl:call-template>
1006 <xsl:variable name="object" select="$olist[position() = $object.index]"/>
1009 <xsl:when test="$object/descendant::d:imagedata[@format = 'GIF' or
1010 @format = 'GIF87a' or
1011 @format = 'GIF89a' or
1016 <xsl:apply-templates select="$object[descendant::d:imagedata[@format = 'GIF' or
1017 @format = 'GIF87a' or
1018 @format = 'GIF89a' or
1022 @format = 'SVG']][1]/d:imagedata"
1023 mode="opf.manifest"/>
1026 <xsl:apply-templates select="$object/d:imagedata[1]"
1027 mode="opf.manifest"/>
1032 <xsl:template match="d:cover/d:mediaobject|
1033 d:mediaobject[@role='cover']"
1034 mode="opf.manifest">
1036 <xsl:when test="d:imageobject[@role='front-large']">
1037 <xsl:apply-templates select="d:imageobject[@role='front-large']/d:imagedata"
1038 mode="opf.manifest"/>
1041 <xsl:apply-templates select="d:imageobject/d:imagedata[1]"
1042 mode="opf.manifest"/>
1047 <xsl:template match="d:mediaobjectco"
1048 mode="opf.manifest">
1049 <xsl:message>WARNING: mediaobjectco almost certainly will not render as expected in .epub!</xsl:message>
1050 <xsl:apply-templates select="d:imageobjectco/d:imageobject/d:imagedata"
1051 mode="opf.manifest"/>
1054 <!-- 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?] -->
1056 <!-- wish I had XSLT2 ...-->
1057 <!-- TODO: priority a hack -->
1058 <xsl:template match="d:graphic[not(@format)]|
1059 d:inlinegraphic[not(@format)]|
1060 d:imagedata[not(@format)]"
1061 mode="opf.manifest">
1062 <xsl:variable name="filename">
1064 <xsl:when test="contains(name(.), 'graphic')">
1066 <xsl:when test="@entityref">
1067 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
1070 <xsl:apply-templates select="@fileref"/>
1075 <xsl:call-template name="mediaobject.filename">
1076 <xsl:with-param name="object" select=".."/>
1077 </xsl:call-template>
1081 <xsl:variable name="format">
1082 <xsl:call-template name="guess-media-type">
1083 <xsl:with-param name="ext" select="@fileref"/>
1084 </xsl:call-template>
1086 <xsl:variable name="fr" select="@fileref"/>
1087 <xsl:if test="$format != ''">
1088 <!-- only do this if we're the first file to match -->
1089 <!-- TODO: Why can't this be simple equality?? (I couldn't get it to work) -->
1090 <xsl:if test="generate-id(.) = generate-id(key('image-filerefs', $fr)[1])">
1091 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
1092 <xsl:attribute name="id">
1094 <xsl:when test="ancestor::d:mediaobject[@role='cover'] and parent::*[@role='front-large']">
1095 <xsl:value-of select="$epub.cover.image.id"/>
1097 <xsl:when test="ancestor::d:mediaobject[@role='cover'] and (count(ancestor::d:mediaobject//d:imageobject) = 1)">
1098 <xsl:value-of select="$epub.cover.image.id"/>
1100 <xsl:when test="ancestor::d:cover">
1101 <xsl:value-of select="$epub.cover.image.id"/>
1104 <xsl:value-of select="generate-id(.)"/>
1108 <xsl:attribute name="href"> <xsl:value-of select="$filename"/> </xsl:attribute>
1109 <xsl:attribute name="media-type">
1110 <xsl:value-of select="$format"/>
1117 <!-- Note: Selection of the first interesting imagedata is done in the select -->
1118 <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']|
1119 d:inlinegraphic[@format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or @format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or @format = 'SVG']|
1120 d:imagedata[@format]"
1121 mode="opf.manifest">
1122 <xsl:variable name="filename">
1124 <xsl:when test="contains(name(.), 'graphic')">
1126 <xsl:when test="@entityref">
1127 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
1130 <xsl:apply-templates select="@fileref"/>
1135 <xsl:call-template name="mediaobject.filename">
1136 <xsl:with-param name="object" select=".."/>
1137 </xsl:call-template>
1141 <xsl:variable name="fr" select="@fileref"/>
1142 <!-- only do this if we're the first file to match -->
1143 <!-- TODO: Why can't this be simple equality?? (I couldn't get it to work) -->
1144 <xsl:if test="generate-id(.) = generate-id(key('image-filerefs', $fr)[1])">
1145 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
1146 <xsl:attribute name="id">
1148 <xsl:when test="ancestor::d:mediaobject[@role='cover'] and parent::*[@role='front-large']">
1149 <xsl:value-of select="$epub.cover.image.id"/>
1151 <xsl:when test="ancestor::d:mediaobject[@role='cover'] and (count(ancestor::d:mediaobject//d:imageobject) = 1)">
1152 <xsl:value-of select="$epub.cover.image.id"/>
1154 <xsl:when test="ancestor::d:cover">
1155 <xsl:value-of select="$epub.cover.image.id"/>
1158 <xsl:value-of select="generate-id(.)"/>
1162 <xsl:attribute name="href"> <xsl:value-of select="$filename"/> </xsl:attribute>
1163 <xsl:attribute name="media-type">
1164 <xsl:call-template name="guess-media-type">
1165 <xsl:with-param name="ext" select="@format"/>
1166 </xsl:call-template>
1172 <!-- Warning: While the test indicate this match list is accurate, it may
1173 need further tweaking to ensure _never_ dropping generated content (XHTML)
1174 from the manifest (OPF file) -->
1177 d:book[parent::d:set]|
1178 d:book[*[last()][self::d:bookinfo]]|
1180 d:book[*[last()][self::d:info]]|
1198 d:bibliodiv[d:title]|
1201 mode="opf.manifest">
1202 <xsl:variable name="href">
1203 <xsl:call-template name="href.target.with.base.dir">
1204 <xsl:with-param name="context" select="/" />
1205 <!-- Generate links relative to the location of root file/toc.xml file -->
1206 </xsl:call-template>
1209 <xsl:variable name="id">
1210 <xsl:value-of select="generate-id(.)"/>
1213 <xsl:variable name="is.chunk">
1214 <xsl:call-template name="chunk">
1215 <xsl:with-param name="node" select="."/>
1216 </xsl:call-template>
1219 <xsl:if test="$is.chunk != 0">
1220 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
1221 <xsl:attribute name="id"> <xsl:value-of select="$id"/> </xsl:attribute>
1222 <xsl:attribute name="href"> <xsl:value-of select="$href"/> </xsl:attribute>
1223 <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
1228 <xsl:template match="text()" mode="ncx" />
1230 <xsl:template name="html.head">
1231 <xsl:param name="prev" select="/d:foo"/>
1232 <xsl:param name="next" select="/d:foo"/>
1233 <xsl:variable name="this" select="."/>
1234 <xsl:variable name="home" select="/*[1]"/>
1235 <xsl:variable name="up" select="parent::*"/>
1237 <head xmlns="http://www.w3.org/1999/xhtml">
1238 <xsl:call-template name="system.head.content"/>
1239 <xsl:call-template name="head.content"/>
1241 <xsl:call-template name="user.head.content"/>
1245 <!-- OVERRIDES xhtml-1_1/graphics.xsl -->
1246 <!-- we can't deal with no img/@alt, because it's required. Try grabbing a title before it instead (hopefully meaningful) -->
1247 <xsl:template name="process.image.attributes">
1248 <xsl:param name="alt"/>
1249 <xsl:param name="html.width"/>
1250 <xsl:param name="html.depth"/>
1251 <xsl:param name="longdesc"/>
1252 <xsl:param name="scale"/>
1253 <xsl:param name="scalefit"/>
1254 <xsl:param name="scaled.contentdepth"/>
1255 <xsl:param name="scaled.contentwidth"/>
1256 <xsl:param name="viewport"/>
1259 <xsl:when test="@contentwidth or @contentdepth">
1260 <!-- ignore @width/@depth, @scale, and @scalefit if specified -->
1261 <xsl:if test="@contentwidth and $scaled.contentwidth != ''">
1262 <xsl:attribute name="width">
1263 <xsl:value-of select="$scaled.contentwidth"/>
1266 <xsl:if test="@contentdepth and $scaled.contentdepth != ''">
1267 <xsl:attribute name="height">
1268 <xsl:value-of select="$scaled.contentdepth"/>
1273 <xsl:when test="number($scale) != 1.0">
1274 <!-- scaling is always uniform, so we only have to specify one dimension -->
1275 <!-- ignore @scalefit if specified -->
1276 <xsl:attribute name="width">
1277 <xsl:value-of select="$scaled.contentwidth"/>
1281 <xsl:when test="$scalefit != 0">
1283 <xsl:when test="contains($html.width, '%')">
1285 <xsl:when test="$viewport != 0">
1286 <!-- The *viewport* will be scaled, so use 100% here! -->
1287 <xsl:attribute name="width">
1288 <xsl:value-of select="'100%'"/>
1292 <xsl:attribute name="width">
1293 <xsl:value-of select="$html.width"/>
1299 <xsl:when test="contains($html.depth, '%')">
1300 <!-- HTML doesn't deal with this case very well...do nothing -->
1303 <xsl:when test="$scaled.contentwidth != '' and $html.width != '' and $scaled.contentdepth != '' and $html.depth != ''">
1304 <!-- scalefit should not be anamorphic; figure out which direction -->
1305 <!-- has the limiting scale factor and scale in that direction -->
1307 <xsl:when test="$html.width div $scaled.contentwidth > $html.depth div $scaled.contentdepth">
1308 <xsl:attribute name="height">
1309 <xsl:value-of select="$html.depth"/>
1313 <xsl:attribute name="width">
1314 <xsl:value-of select="$html.width"/>
1320 <xsl:when test="$scaled.contentwidth != '' and $html.width != ''">
1321 <xsl:attribute name="width">
1322 <xsl:value-of select="$html.width"/>
1326 <xsl:when test="$scaled.contentdepth != '' and $html.depth != ''">
1327 <xsl:attribute name="height">
1328 <xsl:value-of select="$html.depth"/>
1335 <!-- AN OVERRIDE -->
1336 <xsl:if test="not(@format ='SVG')">
1337 <xsl:attribute name="alt">
1339 <xsl:when test="$alt != ''">
1340 <xsl:value-of select="normalize-space($alt)"/>
1342 <xsl:when test="preceding::d:title[1]">
1343 <xsl:value-of select="normalize-space(preceding::d:title[1])"/>
1346 <xsl:text>(missing alt)</xsl:text>
1351 <!-- END OF OVERRIDE -->
1353 <xsl:if test="$longdesc != ''">
1354 <xsl:attribute name="longdesc">
1355 <xsl:value-of select="$longdesc"/>
1359 <xsl:if test="@align and $viewport = 0">
1360 <xsl:attribute name="style"><xsl:text>text-align: </xsl:text>
1362 <xsl:when test="@align = 'center'">middle</xsl:when>
1364 <xsl:value-of select="@align"/>
1371 <!-- OVERRIDES xhtml-1_1/chunk-common.xsl -->
1372 <!-- make a bibliography always a chunk -->
1373 <xsl:template name="chunk">
1374 <xsl:param name="node" select="."/>
1375 <!-- returns 1 if $node is a chunk -->
1377 <!-- ==================================================================== -->
1378 <!-- What's a chunk?
1383 bibliography ### NO LONGER TRUE in article or part or book
1387 glossary in article or part or book
1388 index in article or part or book
1393 sect{1,2,3,4,5} if position()>1 && depth < chunk.section.depth
1394 section if position()>1 && depth < chunk.section.depth
1398 <!-- ==================================================================== -->
1402 <xsl:text>chunk: </xsl:text>
1403 <xsl:value-of select="name($node)"/>
1404 <xsl:text>(</xsl:text>
1405 <xsl:value-of select="$node/@id"/>
1406 <xsl:text>)</xsl:text>
1407 <xsl:text> csd: </xsl:text>
1408 <xsl:value-of select="$chunk.section.depth"/>
1409 <xsl:text> cfs: </xsl:text>
1410 <xsl:value-of select="$chunk.first.sections"/>
1411 <xsl:text> ps: </xsl:text>
1412 <xsl:value-of select="count($node/parent::d:section)"/>
1413 <xsl:text> prs: </xsl:text>
1414 <xsl:value-of select="count($node/preceding-sibling::d:section)"/>
1419 <xsl:when test="not($node/parent::*)">1</xsl:when>
1421 <xsl:when test="local-name($node) = 'sect1' and $chunk.section.depth >= 1 and ($chunk.first.sections != 0 or count($node/preceding-sibling::d:sect1) > 0)">
1422 <xsl:text>1</xsl:text>
1424 <xsl:when test="local-name($node) = 'sect2' and $chunk.section.depth >= 2 and ($chunk.first.sections != 0 or count($node/preceding-sibling::d:sect2) > 0)">
1425 <xsl:call-template name="chunk">
1426 <xsl:with-param name="node" select="$node/parent::*"/>
1427 </xsl:call-template>
1429 <xsl:when test="local-name($node) = 'sect3' and $chunk.section.depth >= 3 and ($chunk.first.sections != 0 or count($node/preceding-sibling::d:sect3) > 0)">
1430 <xsl:call-template name="chunk">
1431 <xsl:with-param name="node" select="$node/parent::*"/>
1432 </xsl:call-template>
1434 <xsl:when test="local-name($node) = 'sect4' and $chunk.section.depth >= 4 and ($chunk.first.sections != 0 or count($node/preceding-sibling::d:sect4) > 0)">
1435 <xsl:call-template name="chunk">
1436 <xsl:with-param name="node" select="$node/parent::*"/>
1437 </xsl:call-template>
1439 <xsl:when test="local-name($node) = 'sect5' and $chunk.section.depth >= 5 and ($chunk.first.sections != 0 or count($node/preceding-sibling::d:sect5) > 0)">
1440 <xsl:call-template name="chunk">
1441 <xsl:with-param name="node" select="$node/parent::*"/>
1442 </xsl:call-template>
1444 <xsl:when test="local-name($node) = 'section' and $chunk.section.depth >= count($node/ancestor::d:section)+1 and ($chunk.first.sections != 0 or count($node/preceding-sibling::d:section) > 0)">
1445 <xsl:call-template name="chunk">
1446 <xsl:with-param name="node" select="$node/parent::*"/>
1447 </xsl:call-template>
1450 <xsl:when test="local-name($node)='preface'">1</xsl:when>
1451 <xsl:when test="local-name($node)='chapter'">1</xsl:when>
1452 <xsl:when test="local-name($node)='appendix'">1</xsl:when>
1453 <xsl:when test="local-name($node)='article'">1</xsl:when>
1454 <xsl:when test="local-name($node)='part'">1</xsl:when>
1455 <xsl:when test="local-name($node)='reference'">1</xsl:when>
1456 <xsl:when test="local-name($node)='refentry'">1</xsl:when>
1457 <xsl:when test="local-name($node)='index' and ($generate.index != 0 or count($node/*) > 0) and (local-name($node/parent::*) = 'article' or local-name($node/parent::*) = 'book' or local-name($node/parent::*) = 'part' )">1</xsl:when>
1458 <!-- AN OVERRIDE -->
1459 <xsl:when test="local-name($node)='bibliography'">1</xsl:when>
1460 <!-- END OF OVERRIDE -->
1461 <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>
1462 <xsl:when test="local-name($node)='colophon'">1</xsl:when>
1463 <xsl:when test="local-name($node)='book'">1</xsl:when>
1464 <xsl:when test="local-name($node)='set'">1</xsl:when>
1465 <xsl:when test="local-name($node)='setindex'">1</xsl:when>
1466 <xsl:when test="local-name($node)='legalnotice' and $generate.legalnotice.link != 0">1</xsl:when>
1467 <xsl:otherwise>0</xsl:otherwise>
1471 <!-- OVERRIDES xhtml-1_1/chunk-code.xsl -->
1472 <!-- Add chunking for bibliography as root element -->
1473 <!-- AN OVERRIDE -->
1474 <xsl:template match="d:set|
1484 d:article/d:glossary|
1489 <!-- END OF OVERRIDE -->
1491 <xsl:when test="$onechunk != 0 and parent::*">
1492 <xsl:apply-imports/>
1495 <xsl:call-template name="process-chunk-element"/>
1500 <!-- OVERRIDES xhtml-1_1/graphics.xsl -->
1501 <!-- Do _NOT_ output any xlink garbage, so if you don't have
1502 processor with extensions, you're screwed and we're terminating -->
1503 <xsl:template match="d:inlinegraphic">
1504 <xsl:variable name="filename">
1506 <xsl:when test="@entityref">
1507 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
1510 <xsl:apply-templates select="@fileref"/>
1515 <xsl:call-template name="anchor"/>
1518 <xsl:when test="@format='linespecific'">
1520 <xsl:when test="$use.extensions != '0' and $textinsert.extension != '0'">
1522 <xsl:when test="element-available('stext:insertfile')">
1523 <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
1525 <xsl:when test="element-available('xtext:insertfile')">
1526 <xtext:insertfile href="{$filename}"/>
1529 <xsl:message terminate="yes">
1530 <xsl:text>No insertfile extension available.</xsl:text>
1536 <!-- AN OVERRIDE -->
1537 <xsl:message terminate="yes">
1538 <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>
1540 <!-- END OF OVERRIDE -->
1545 <xsl:call-template name="process.image"/>
1550 <xsl:template name="cover">
1551 <xsl:apply-templates select="/*/*[contains(name(.), 'info')]//d:mediaobject[@role='cover' or ancestor::d:cover]"/>
1554 <xsl:template match="/*/*[d:cover or contains(name(.), 'info')]//d:mediaobject[@role='cover' or ancestor::d:cover]">
1555 <xsl:call-template name="write.chunk">
1556 <xsl:with-param name="filename">
1557 <xsl:value-of select="$epub.cover.filename" />
1559 <xsl:with-param name="method" select="'xml'" />
1560 <xsl:with-param name="encoding" select="'utf-8'" />
1561 <xsl:with-param name="indent" select="'no'" />
1562 <xsl:with-param name="quiet" select="$chunk.quietly" />
1563 <xsl:with-param name="content">
1564 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="html">
1565 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="head">
1566 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="title">Cover</xsl:element>
1567 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="style">
1568 <xsl:attribute name="type">text/css</xsl:attribute>
1569 <!-- Help the cover image scale nicely in the CSS then apply a max-width to look better in Adobe Digital Editions -->
1570 <xsl:text> img { max-width: 100%; }</xsl:text>
1573 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="body">
1574 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="div">
1575 <xsl:attribute name="id">
1576 <xsl:value-of select="$epub.cover.image.id"/>
1579 <xsl:when test="d:imageobject[@role='front-large']">
1580 <xsl:apply-templates select="d:imageobject[@role='front-large']"/>
1583 <xsl:apply-templates select="d:imageobject[1]"/>
1587 <!-- If this is defined as an explicit cover page, then process
1588 any remaining text -->
1589 <xsl:if test="ancestor::d:cover">
1590 <xsl:apply-templates select="ancestor::d:cover/d:para"/>
1595 </xsl:call-template>
1598 <xsl:template name="cover-svg">
1599 <xsl:param name="node"/>
1602 <xsl:template name="toc-href">
1603 <xsl:param name="node" select="."/>
1604 <xsl:apply-templates select="$node" mode="recursive-chunk-filename">
1605 <xsl:with-param name="recursive" select="true()"/>
1606 </xsl:apply-templates>
1607 <xsl:text>-toc</xsl:text>
1608 <xsl:value-of select="$html.ext"/>
1611 <xsl:template match="d:bibliodiv[d:title]" mode="label.markup">
1614 <xsl:template match="d:token" mode="opf.manifest.font">
1615 <xsl:call-template name="embedded-font-item">
1616 <xsl:with-param name="font.file" select="."/>
1617 </xsl:call-template>
1620 <xsl:template name="embedded-font-item">
1621 <xsl:param name="font.file"/>
1622 <xsl:param name="font.order" select="1"/>
1624 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
1625 <xsl:attribute name="id">
1626 <xsl:value-of select="concat('epub.embedded.font.', $font.order)"/>
1628 <xsl:attribute name="href"><xsl:value-of select="$font.file"/></xsl:attribute>
1630 <xsl:when test="contains($font.file, 'otf')">
1631 <xsl:attribute name="media-type">font/opentype</xsl:attribute>
1635 <xsl:text>WARNING: OpenType fonts should be supplied! (</xsl:text>
1636 <xsl:value-of select="$font.file"/>
1637 <xsl:text>)</xsl:text>
1644 <!-- Change section.heading to improve SEO on generated HTML by doing heading levels
1645 "correctly". SEO rules are sometimes silly silly, but this does actually create
1646 a semantic improvement.
1647 Note: This template needs to be manually maintained outside of the html/sections.xsl
1648 code, so make sure important changes get reintegrated. -->
1649 <xsl:template name="section.heading">
1650 <xsl:param name="section" select="."/>
1651 <xsl:param name="level" select="1"/>
1652 <xsl:param name="allow-anchors" select="1"/>
1653 <xsl:param name="title"/>
1654 <xsl:param name="class" select="'title'"/>
1656 <xsl:variable name="id">
1658 <!-- Make sure the subtitle doesn't get the same id as the title -->
1659 <xsl:when test="self::d:subtitle">
1660 <xsl:call-template name="object.id">
1661 <xsl:with-param name="object" select="."/>
1662 </xsl:call-template>
1664 <!-- if title is in an *info wrapper, get the grandparent -->
1665 <xsl:when test="contains(local-name(..), 'info')">
1666 <xsl:call-template name="object.id">
1667 <xsl:with-param name="object" select="../.."/>
1668 </xsl:call-template>
1671 <xsl:call-template name="object.id">
1672 <xsl:with-param name="object" select=".."/>
1673 </xsl:call-template>
1678 <!-- For SEO, we try to actually ensure we *always* output one and only one h1,
1679 so unlike the regular stylesheets, we don't add one to the section level and
1680 we get the right behavior because of chunking. -->
1681 <xsl:variable name="hlevel">
1683 <!-- highest valid HTML H level is H6; so anything nested deeper
1684 than 7 levels down just becomes H6 -->
1685 <xsl:when test="$level > 6">6</xsl:when>
1687 <xsl:value-of select="$level"/>
1691 <xsl:element name="h{$hlevel}" namespace="http://www.w3.org/1999/xhtml">
1692 <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
1693 <xsl:if test="$css.decoration != '0'">
1694 <xsl:if test="$hlevel<3">
1695 <xsl:attribute name="style">clear: both</xsl:attribute>
1698 <xsl:if test="$allow-anchors != 0 and $generate.id.attributes = 0">
1699 <xsl:call-template name="anchor">
1700 <xsl:with-param name="node" select="$section"/>
1701 <xsl:with-param name="conditional" select="0"/>
1702 </xsl:call-template>
1704 <xsl:if test="$generate.id.attributes != 0 and not(local-name(.) = 'appendix')">
1705 <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
1707 <xsl:copy-of select="$title"/>
1711 <!-- ==================================================================== -->
1713 <xsl:template match="d:bridgehead">
1714 <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()]"/>
1716 <xsl:variable name="clevel">
1718 <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>
1719 <xsl:when test="local-name($container) = 'glossdiv'">
1720 <xsl:value-of select="count(ancestor::d:glossdiv)+1"/>
1722 <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'">
1723 <xsl:variable name="slevel">
1724 <xsl:call-template name="section.level">
1725 <xsl:with-param name="node" select="$container"/>
1726 </xsl:call-template>
1728 <xsl:value-of select="$slevel + 1"/>
1730 <xsl:otherwise>1</xsl:otherwise>
1734 <!-- HTML H level is one higher than section level -->
1735 <xsl:variable name="hlevel">
1737 <xsl:when test="@renderas = 'sect1'">1</xsl:when>
1738 <xsl:when test="@renderas = 'sect2'">2</xsl:when>
1739 <xsl:when test="@renderas = 'sect3'">3</xsl:when>
1740 <xsl:when test="@renderas = 'sect4'">4</xsl:when>
1741 <xsl:when test="@renderas = 'sect5'">5</xsl:when>
1743 <xsl:value-of select="$clevel + 1"/>
1748 <xsl:element name="h{$hlevel}" namespace="http://www.w3.org/1999/xhtml">
1749 <xsl:call-template name="anchor">
1750 <xsl:with-param name="conditional" select="0"/>
1751 </xsl:call-template>
1752 <xsl:apply-templates/>
1756 <!-- SEO customization #2 -->
1757 <xsl:template name="component.title">
1758 <xsl:param name="node" select="."/>
1760 <xsl:variable name="level">
1762 <xsl:when test="ancestor::d:section">
1763 <xsl:value-of select="count(ancestor::d:section)+1"/>
1765 <xsl:when test="ancestor::d:sect5">6</xsl:when>
1766 <xsl:when test="ancestor::d:sect4">5</xsl:when>
1767 <xsl:when test="ancestor::d:sect3">4</xsl:when>
1768 <xsl:when test="ancestor::d:sect2">3</xsl:when>
1769 <xsl:when test="ancestor::d:sect1">2</xsl:when>
1770 <xsl:otherwise>1</xsl:otherwise>
1774 <xsl:element name="h{$level}" namespace="http://www.w3.org/1999/xhtml">
1775 <xsl:attribute name="class">title</xsl:attribute>
1776 <xsl:if test="$generate.id.attributes = 0">
1777 <xsl:call-template name="anchor">
1778 <xsl:with-param name="node" select="$node"/>
1779 <xsl:with-param name="conditional" select="0"/>
1780 </xsl:call-template>
1782 <xsl:apply-templates select="$node" mode="object.title.markup">
1783 <xsl:with-param name="allow-anchors" select="1"/>
1784 </xsl:apply-templates>
1788 <xsl:template name="css.item">
1789 <xsl:param name="stylesheets" select="''"/>
1790 <xsl:param name="count" select="1"/>
1792 <xsl:variable name="opf.namespace">http://www.idpf.org/2007/opf</xsl:variable>
1795 <xsl:when test="contains($stylesheets, ' ')">
1796 <xsl:variable name="css.filename" select="substring-before($stylesheets, ' ')"/>
1797 <xsl:if test="$css.filename != ''">
1798 <xsl:element namespace="{$opf.namespace}" name="item">
1799 <xsl:attribute name="media-type">text/css</xsl:attribute>
1800 <xsl:attribute name="id">
1801 <xsl:text>html-css</xsl:text>
1802 <xsl:if test="$count > 1">
1803 <xsl:value-of select="$count"/>
1806 <xsl:attribute name="href">
1807 <xsl:value-of select="$css.filename"/>
1812 <xsl:call-template name="css.item">
1813 <xsl:with-param name="stylesheets" select="substring-after($stylesheets, ' ')"/>
1814 <xsl:with-param name="count" select="$count + 1"/>
1815 </xsl:call-template>
1818 <xsl:if test="$stylesheets != ''">
1819 <xsl:element namespace="{$opf.namespace}" name="item">
1820 <xsl:attribute name="media-type">text/css</xsl:attribute>
1821 <xsl:attribute name="id">
1822 <xsl:text>html-css</xsl:text>
1823 <xsl:if test="$count > 1">
1824 <xsl:value-of select="$count"/>
1827 <xsl:attribute name="href">
1828 <xsl:value-of select="$stylesheets"/>