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:xsl="http://www.w3.org/1999/XSL/Transform"
13 xmlns:xtext="xalan://com.nwalsh.xalan.Text"
15 extension-element-prefixes="stext xtext"
16 exclude-result-prefixes="exsl db dc h ncx ng opf stext str xtext"
20 <xsl:import href="../xhtml-1_1/docbook.xsl" />
21 <xsl:import href="../xhtml-1_1/chunk-common.xsl" />
22 <xsl:include href="../xhtml-1_1/chunk-code.xsl" />
25 <!-- We want a separate TOC file, please -->
26 <xsl:param name="chunk.tocs.and.lots">1</xsl:param>
27 <xsl:param name="toc.section.depth">2</xsl:param>
28 <xsl:param name="generate.toc">
32 <xsl:param name="ade.extensions" select="0"/>
33 <xsl:param name="epub.autolabel" select="'1'"/>
34 <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 <xsl:param name="manifest.in.base.dir" select="'1'"/>
38 <xsl:param name="base.dir" select="$epub.oebps.dir"/>
40 <xsl:param name="epub.oebps.dir" select="'OEBPS/'"/>
41 <xsl:param name="epub.ncx.filename" select="'toc.ncx'"/>
42 <xsl:param name="epub.container.filename" select="'container.xml'"/>
43 <xsl:param name="epub.opf.filename" select="concat($epub.oebps.dir, 'content.opf')"/>
44 <xsl:param name="epub.cover.filename" select="concat($epub.oebps.dir, 'cover', $html.ext)"/>
45 <xsl:param name="epub.cover.id" select="'cover'"/>
46 <xsl:param name="epub.cover.html" select="'cover.html'" />
47 <xsl:param name="epub.cover.image.id" select="'cover-image'"/>
48 <xsl:param name="epub.cover.linear" select="0" />
49 <xsl:param name="epub.ncx.toc.id">ncxtoc</xsl:param>
50 <xsl:param name="epub.html.toc.id">htmltoc</xsl:param>
51 <xsl:param name="epub.metainf.dir" select="'META-INF/'"/>
53 <xsl:param name="epub.embedded.fonts"></xsl:param>
55 <!-- Turning this on crashes ADE, which is unbelievably awesome -->
56 <xsl:param name="formal.object.break.after">0</xsl:param>
60 """Process your documents with the css.decoration parameter set to zero.
61 That will avoid the use of style attributes in XHTML elements where they are not permitted."""
62 http://www.sagehill.net/docbookxsl/OtherOutputForms.html#StrictXhtmlValid -->
63 <xsl:param name="css.decoration" select="0"/>
64 <xsl:param name="custom.css.source"></xsl:param> <!-- FIXME: Align with current CSS parameter design -->
66 <xsl:param name="callout.graphics" select="1"/>
67 <xsl:param name="callout.graphics.extension">.png</xsl:param>
68 <xsl:param name="callout.graphics.number.limit" select="15"/>
69 <xsl:param name="callout.graphics.path" select="'images/callouts/'"/>
71 <!-- no navigation in .epub -->
72 <xsl:param name="suppress.navigation" select="'1'"/>
74 <xsl:variable name="toc.params">
75 <xsl:call-template name="find.path.params">
76 <xsl:with-param name="node" select="/*"/>
77 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
80 <xsl:variable name="root.is.a.chunk">
82 <xsl:when test="/*[not(self::book)][not(sect1) or not(section)]">
83 <xsl:text>1</xsl:text>
85 <xsl:when test="/book[*[last()][self::bookinfo]]|book[bookinfo]">
86 <xsl:text>1</xsl:text>
88 <xsl:when test="/book[*[last()][self::info]]|book[info]">
89 <xsl:text>1</xsl:text>
91 <xsl:when test="/bibliography">
92 <xsl:text>1</xsl:text>
95 <xsl:text>0</xsl:text>
100 <xsl:key name="image-filerefs" match="graphic|inlinegraphic|imagedata" use="@fileref"/>
102 <xsl:template match="/">
103 <!-- * Get a title for current doc so that we let the user -->
104 <!-- * know what document we are processing at this point. -->
105 <xsl:variable name="doc.title">
106 <xsl:call-template name="get.doc.title" />
109 <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
110 toss the namespace and continue. Use the docbook5 namespaced
111 stylesheets for DocBook5 if you don't want to use this feature.-->
112 <!-- include extra test for Xalan quirk -->
113 <xsl:when test="$exsl.node.set.available != 0
114 and (*/self::ng:* or */self::db:*)">
115 <xsl:call-template name="log.message">
116 <xsl:with-param name="level">Note</xsl:with-param>
117 <xsl:with-param name="source" select="$doc.title" />
118 <xsl:with-param name="context-desc">
119 <xsl:text>namesp. cut</xsl:text>
121 <xsl:with-param name="message">
122 <xsl:text>stripped namespace before processing</xsl:text>
125 <xsl:variable name="nons">
126 <xsl:apply-templates mode="stripNS" />
128 <xsl:call-template name="log.message">
129 <xsl:with-param name="level">Note</xsl:with-param>
130 <xsl:with-param name="source" select="$doc.title" />
131 <xsl:with-param name="context-desc">
132 <xsl:text>namesp. cut</xsl:text>
134 <xsl:with-param name="message">
135 <xsl:text>processing stripped document</xsl:text>
138 <xsl:apply-templates select="exsl:node-set($nons)" />
142 <xsl:when test="$rootid != ''">
145 test="count(key('id',$rootid)) = 0">
146 <xsl:message terminate="yes">
147 <xsl:text>ID '</xsl:text>
148 <xsl:value-of select="$rootid" />
149 <xsl:text>' not found in document.</xsl:text>
154 test="$collect.xref.targets = 'yes' or
155 $collect.xref.targets = 'only'">
157 select="key('id', $rootid)" mode="collect.targets" />
160 test="$collect.xref.targets != 'only'">
163 <xsl:value-of select="$rootid" />
166 select="key('id',$rootid)" mode="process.root" />
167 <xsl:call-template name="ncx" />
174 test="$collect.xref.targets = 'yes' or
175 $collect.xref.targets = 'only'">
176 <xsl:apply-templates select="/"
177 mode="collect.targets" />
180 test="$collect.xref.targets != 'only'">
181 <xsl:apply-templates select="/"
182 mode="process.root" />
183 <xsl:call-template name="ncx" />
184 <xsl:call-template name="opf" />
185 <xsl:call-template name="cover" />
186 <xsl:call-template name="container" />
194 <xsl:template name="package-identifier">
196 <xsl:when test="/*/*[contains(name(.), 'info')]/biblioid">
197 <xsl:if test="/*/*[contains(name(.), 'info')][1]/biblioid[1][@class = 'doi' or
201 <xsl:text>urn:</xsl:text>
202 <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/biblioid[1]/@class"/>
203 <xsl:text>:</xsl:text>
205 <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/biblioid[1]"/>
207 <xsl:when test="/*/*[contains(name(.), 'info')]/isbn">
208 <xsl:text>urn:isbn:</xsl:text>
209 <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/isbn[1]"/>
211 <xsl:when test="/*/*[contains(name(.), 'info')]/issn">
212 <xsl:text>urn:issn:</xsl:text>
213 <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/issn[1]"/>
217 <xsl:when test="/*/*[contains(name(.), 'info')]/invpartnumber"> <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/invpartnumber[1]"/> </xsl:when>
218 <xsl:when test="/*/*[contains(name(.), 'info')]/issuenum"> <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/issuenum[1]"/> </xsl:when>
219 <xsl:when test="/*/*[contains(name(.), 'info')]/productnumber"> <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/productnumber[1]"/> </xsl:when>
220 <xsl:when test="/*/*[contains(name(.), 'info')]/seriesvolnums"> <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/seriesvolnums[1]"/> </xsl:when>
221 <xsl:when test="/*/*[contains(name(.), 'info')]/volumenum"> <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/volumenum[1]"/> </xsl:when>
223 <xsl:when test="/*/*[contains(name(.), 'info')]/pubsnumber"> <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/pubsnumber[1]"/> </xsl:when>
225 <xsl:text>_</xsl:text>
227 <xsl:when test="/*/@id">
228 <xsl:value-of select="/*/@id"/>
230 <xsl:when test="/*/@xml:id">
231 <xsl:value-of select="/*/@xml:id"/>
234 <!-- TODO: Do UUIDs here -->
235 <xsl:value-of select="generate-id(/*)"/>
242 <xsl:template name="opf">
243 <xsl:variable name="package-identifier-id"><xsl:value-of select="concat(name(/*), 'id')"/></xsl:variable>
244 <xsl:variable name="doc.title">
245 <xsl:call-template name="get.doc.title" />
247 <xsl:call-template name="write.chunk">
248 <xsl:with-param name="filename">
249 <xsl:value-of select="$epub.opf.filename" />
251 <xsl:with-param name="method" select="'xml'" />
252 <xsl:with-param name="encoding" select="'utf-8'" />
253 <xsl:with-param name="indent" select="'no'" />
254 <xsl:with-param name="quiet" select="$chunk.quietly" />
255 <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
256 <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
257 <xsl:with-param name="content">
258 <xsl:element namespace="http://www.idpf.org/2007/opf" name="package">
259 <xsl:attribute name="version">2.0</xsl:attribute>
260 <xsl:attribute name="unique-identifier"> <xsl:value-of select="$package-identifier-id"/> </xsl:attribute>
262 <xsl:element namespace="http://www.idpf.org/2007/opf" name="metadata">
263 <xsl:element name="dc:identifier">
264 <xsl:attribute name="id"><xsl:value-of select="$package-identifier-id"/></xsl:attribute>
265 <xsl:call-template name="package-identifier"/>
268 <xsl:element name="dc:title">
269 <xsl:value-of select="normalize-space($doc.title)"/>
272 <xsl:apply-templates select="/*/*[contains(name(.), 'info')]/*"
273 mode="opf.metadata"/>
274 <xsl:element name="dc:language">
275 <xsl:call-template name="l10n.language">
276 <xsl:with-param name="target" select="/*"/>
280 <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]">
281 <xsl:element namespace="http://www.idpf.org/2007/opf" name="meta">
282 <xsl:attribute name="name">cover</xsl:attribute>
283 <xsl:attribute name="content">
284 <xsl:value-of select="$epub.cover.image.id"/>
290 <xsl:call-template name="opf.manifest"/>
291 <xsl:call-template name="opf.spine"/>
292 <xsl:call-template name="opf.guide"/>
299 <xsl:template name="container">
300 <xsl:call-template name="write.chunk">
301 <xsl:with-param name="filename">
302 <xsl:value-of select="$epub.metainf.dir" />
303 <xsl:value-of select="$epub.container.filename" />
305 <xsl:with-param name="method" select="'xml'" />
306 <xsl:with-param name="encoding" select="'utf-8'" />
307 <xsl:with-param name="indent" select="'no'" />
308 <xsl:with-param name="quiet" select="$chunk.quietly" />
309 <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
310 <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
312 <xsl:with-param name="content">
313 <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="container">
314 <xsl:attribute name="version">1.0</xsl:attribute>
315 <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="rootfiles">
316 <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="rootfile">
317 <xsl:attribute name="full-path">
318 <xsl:value-of select="$epub.opf.filename" />
320 <xsl:attribute name="media-type">
321 <xsl:text>application/oebps-package+xml</xsl:text>
330 <xsl:template name="ncx">
331 <xsl:call-template name="write.chunk">
332 <xsl:with-param name="filename">
333 <xsl:if test="$manifest.in.base.dir != 0">
334 <xsl:value-of select="$base.dir" />
336 <xsl:value-of select="$epub.ncx.filename" />
338 <xsl:with-param name="method" select="'xml'" />
339 <xsl:with-param name="encoding" select="'utf-8'" />
340 <xsl:with-param name="indent" select="'no'" />
341 <xsl:with-param name="quiet" select="$chunk.quietly" />
342 <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
343 <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
344 <xsl:with-param name="content">
345 <xsl:element name="ncx" namespace="http://www.daisy.org/z3986/2005/ncx/">
346 <xsl:attribute name="version">2005-1</xsl:attribute>
348 <!-- Via Martin Goerner: On covers: the IDPF2.0 standard unfortunately does not have a provision for
349 covers. We had to add one and we did so in conjunction with the IDPF and
350 various publishers. The tag chosen to define the covers is:
351 <meta name="cover" content="-reference to a manifest item-">
352 Then, we also added a bit of logic to get rid cleanly of the HTML cover
353 people usually add because the logical cover is not specced by the IDPF. So,
354 if the HTML cover item is marked linear="no" AND there is a guide item of
355 type="cover" pointing to it AND there is a logical cover specified in a
356 <meta name="cover"> tag, THEN, the HTML cover is discarded. -->
357 <xsl:element name="head" namespace="http://www.daisy.org/z3986/2005/ncx/">
358 <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]">
359 <xsl:element name="meta" namespace="http://www.daisy.org/z3986/2005/ncx/">
360 <xsl:attribute name="name">cover</xsl:attribute>
361 <xsl:attribute name="content">
362 <xsl:value-of select="$epub.cover.id"/>
366 <xsl:element name="meta" namespace="http://www.daisy.org/z3986/2005/ncx/">
367 <xsl:attribute name="name">dtb:uid</xsl:attribute>
368 <xsl:attribute name="content"><xsl:call-template name="package-identifier"/></xsl:attribute>
373 <xsl:when test="$rootid != ''">
374 <xsl:variable name="title">
375 <xsl:if test="$epub.autolabel != 0">
376 <xsl:variable name="label.markup">
377 <xsl:apply-templates select="key('id',$rootid)" mode="label.markup" />
379 <xsl:if test="normalize-space($label.markup)">
380 <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
383 <xsl:apply-templates select="key('id',$rootid)" mode="title.markup" />
385 <xsl:variable name="href">
386 <xsl:call-template name="href.target.with.base.dir">
387 <xsl:with-param name="object" select="key('id',$rootid)" />
390 <xsl:element name="docTitle" namespace="http://www.daisy.org/z3986/2005/ncx/">
391 <xsl:element name="text" namespace="http://www.daisy.org/z3986/2005/ncx/"><xsl:value-of select="normalize-space($title)" /> </xsl:element>
393 <xsl:element name="navMap" namespace="http://www.daisy.org/z3986/2005/ncx/">
394 <xsl:apply-templates select="key('id',$rootid)/*" mode="ncx" />
398 <xsl:variable name="title">
399 <xsl:if test="$epub.autolabel != 0">
400 <xsl:variable name="label.markup">
401 <xsl:apply-templates select="/*" mode="label.markup" />
403 <xsl:if test="normalize-space($label.markup)">
404 <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
407 <xsl:apply-templates select="/*" mode="title.markup" />
409 <xsl:variable name="href">
410 <xsl:call-template name="href.target.with.base.dir">
411 <xsl:with-param name="object" select="/" />
414 <xsl:element name="docTitle" namespace="http://www.daisy.org/z3986/2005/ncx/">
415 <xsl:element name="text" namespace="http://www.daisy.org/z3986/2005/ncx/">
416 <xsl:value-of select="normalize-space($title)" />
419 <xsl:element name="navMap" namespace="http://www.daisy.org/z3986/2005/ncx/">
421 <xsl:when test="$root.is.a.chunk != '0'">
422 <xsl:apply-templates select="/*" mode="ncx" />
425 <xsl:apply-templates select="/*/*" mode="ncx" />
437 <xsl:template match="book|
458 <xsl:variable name="depth" select="count(ancestor::*)"/>
459 <xsl:variable name="title">
460 <xsl:if test="$epub.autolabel != 0">
461 <xsl:variable name="label.markup">
462 <xsl:apply-templates select="." mode="label.markup" />
464 <xsl:if test="normalize-space($label.markup)">
466 select="concat($label.markup,$autotoc.label.separator)" />
469 <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="context" select="/" />
475 <!-- Generate links relative to the location of root file/toc.xml file -->
479 <xsl:variable name="id">
480 <xsl:value-of select="generate-id(.)"/>
482 <xsl:variable name="order">
483 <xsl:value-of select="$depth +
484 count(preceding::part|
485 preceding::reference|
486 preceding::book[parent::set]|
489 preceding::bibliography|
493 preceding::section[not(parent::partintro)]|
494 preceding::sect1[not(parent::partintro)]|
495 preceding::sect2[not(ancestor::partintro)]|
496 preceding::sect3[not(ancestor::partintro)]|
497 preceding::sect4[not(ancestor::partintro)]|
498 preceding::sect5[not(ancestor::partintro)]|
501 preceding::bibliodiv[title]|
505 <xsl:element name="navPoint" namespace="http://www.daisy.org/z3986/2005/ncx/">
506 <xsl:attribute name="id">
507 <xsl:value-of select="$id"/>
510 <xsl:attribute name="playOrder">
512 <xsl:when test="/*[self::set]">
513 <xsl:value-of select="$order"/>
515 <xsl:when test="$root.is.a.chunk != '0'">
516 <xsl:value-of select="$order + 1"/>
519 <xsl:value-of select="$order - 0"/>
523 <xsl:element name="navLabel" namespace="http://www.daisy.org/z3986/2005/ncx/">
524 <xsl:element name="text" namespace="http://www.daisy.org/z3986/2005/ncx/"><xsl:value-of select="normalize-space($title)"/> </xsl:element>
526 <xsl:element name="content" namespace="http://www.daisy.org/z3986/2005/ncx/">
527 <xsl:attribute name="src">
528 <xsl:value-of select="$href"/>
531 <xsl:apply-templates select="book[parent::set]|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv[title]|setindex|index" mode="ncx"/>
536 <xsl:template match="*" mode="opf.metadata">
537 <!-- override if you care -->
540 <xsl:template match="authorgroup" mode="opf.metadata">
541 <xsl:apply-templates select="author|corpauthor" mode="opf.metadata"/>
544 <xsl:template match="author|corpauthor" mode="opf.metadata">
545 <xsl:variable name="n">
546 <xsl:call-template name="person.name">
547 <xsl:with-param name="node" select="."/>
550 <xsl:element name="dc:creator">
551 <xsl:attribute name="opf:file-as">
552 <xsl:call-template name="person.name.last-first">
553 <xsl:with-param name="node" select="."/>
556 <xsl:value-of select="normalize-space(string($n))"/>
560 <xsl:template match="date" mode="opf.metadata">
561 <xsl:element name="dc:date">
562 <xsl:value-of select="normalize-space(string(.))"/>
567 <!-- Space separate the compontents of the abstract (dropping the inline markup, sadly) -->
568 <xsl:template match="abstract" mode="opf.metadata">
569 <xsl:element name="dc:description">
570 <xsl:for-each select="formalpara|para|simpara|title">
572 <xsl:when test="self::formalpara">
573 <xsl:value-of select="normalize-space(string(title))"/>
574 <xsl:text>: </xsl:text>
575 <xsl:value-of select="normalize-space(string(para))"/>
578 <xsl:value-of select="normalize-space(string(.))"/>
581 <xsl:if test="self::title">
582 <xsl:text>:</xsl:text>
584 <xsl:if test="not(position() = last())">
585 <xsl:text> </xsl:text>
591 <xsl:template match="subjectset" mode="opf.metadata">
592 <xsl:apply-templates select="subject/subjectterm" mode="opf.metadata"/>
595 <xsl:template match="subjectterm" mode="opf.metadata">
596 <xsl:element name="dc:subject">
597 <xsl:value-of select="normalize-space(string(.))"/>
601 <xsl:template match="publisher" mode="opf.metadata">
602 <xsl:apply-templates select="publishername" mode="opf.metadata"/>
605 <xsl:template match="publishername" mode="opf.metadata">
606 <xsl:element name="dc:publisher">
607 <xsl:value-of select="normalize-space(string(.))"/>
611 <xsl:template match="copyright" mode="opf.metadata">
612 <xsl:variable name="copyright.date">
613 <xsl:call-template name="copyright.years">
614 <xsl:with-param name="years" select="year"/>
615 <xsl:with-param name="print.ranges" select="$make.year.ranges"/>
616 <xsl:with-param name="single.year.ranges" select="$make.single.year.ranges"/>
619 <xsl:if test="not(../date)">
620 <xsl:element name="dc:date">
621 <xsl:call-template name="copyright.years">
622 <xsl:with-param name="years" select="year[last()]"/>
623 <xsl:with-param name="print.ranges" select="0"/>
624 <xsl:with-param name="single.year.ranges" select="0"/>
628 <xsl:element name="dc:rights">
629 <xsl:call-template name="gentext">
630 <xsl:with-param name="key" select="'Copyright'"/>
632 <xsl:call-template name="gentext.space"/>
633 <xsl:text>©</xsl:text>
634 <xsl:call-template name="gentext.space"/>
635 <xsl:value-of select="$copyright.date"/>
636 <xsl:call-template name="gentext.space"/>
637 <xsl:apply-templates select="holder" mode="titlepage.mode"/>
641 <xsl:template name="opf.guide">
642 <xsl:if test="contains($toc.params, 'toc') or
643 /*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]">
644 <xsl:element namespace="http://www.idpf.org/2007/opf" name="guide">
645 <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]">
646 <xsl:element namespace="http://www.idpf.org/2007/opf" name="reference">
647 <xsl:attribute name="href">
648 <xsl:value-of select="$epub.cover.html" />
650 <xsl:attribute name="type">cover</xsl:attribute>
651 <xsl:attribute name="title">Cover</xsl:attribute>
655 <xsl:if test="contains($toc.params, 'toc')">
656 <xsl:element namespace="http://www.idpf.org/2007/opf" name="reference">
657 <xsl:attribute name="href">
658 <xsl:call-template name="toc-href">
659 <xsl:with-param name="node" select="/*"/>
662 <xsl:attribute name="type">toc</xsl:attribute>
663 <xsl:attribute name="title">Table of Contents</xsl:attribute>
670 <xsl:template name="opf.spine">
672 <xsl:element namespace="http://www.idpf.org/2007/opf" name="spine">
673 <xsl:attribute name="toc">
674 <xsl:value-of select="$epub.ncx.toc.id"/>
677 <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]">
678 <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
679 <xsl:attribute name="idref">
680 <xsl:value-of select="$epub.cover.id"/>
682 <xsl:attribute name="linear">
684 <xsl:when test="$epub.cover.linear">
685 <xsl:text>yes</xsl:text>
687 <xsl:otherwise>no</xsl:otherwise>
694 <xsl:if test="contains($toc.params, 'toc')">
695 <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
696 <xsl:attribute name="idref"> <xsl:value-of select="$epub.html.toc.id"/> </xsl:attribute>
697 <xsl:attribute name="linear">yes</xsl:attribute>
701 <!-- TODO: be nice to have a idref="titlepage" here -->
703 <xsl:when test="$root.is.a.chunk != '0'">
704 <xsl:apply-templates select="/*" mode="opf.spine"/>
707 <xsl:apply-templates select="/*/*" mode="opf.spine"/>
714 <xsl:template match="*" mode="opf.spine">
715 <xsl:variable name="is.chunk">
716 <xsl:call-template name="chunk">
717 <xsl:with-param name="node" select="."/>
721 <xsl:if test="$is.chunk != 0">
722 <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
723 <xsl:attribute name="idref">
724 <xsl:value-of select="generate-id(.)"/>
727 <xsl:apply-templates select="*|.//refentry" mode="opf.spine"/>
731 <xsl:template name="opf.manifest">
732 <xsl:element namespace="http://www.idpf.org/2007/opf" name="manifest">
733 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
734 <xsl:attribute name="id"> <xsl:value-of select="$epub.ncx.toc.id"/> </xsl:attribute>
735 <xsl:attribute name="media-type">application/x-dtbncx+xml</xsl:attribute>
736 <xsl:attribute name="href"><xsl:value-of select="$epub.ncx.filename"/> </xsl:attribute>
739 <xsl:if test="contains($toc.params, 'toc')">
740 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
741 <xsl:attribute name="id"> <xsl:value-of select="$epub.html.toc.id"/> </xsl:attribute>
742 <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
743 <xsl:attribute name="href">
744 <xsl:call-template name="toc-href">
745 <xsl:with-param name="node" select="/*"/>
751 <xsl:if test="$html.stylesheet != ''">
752 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
753 <xsl:attribute name="media-type">text/css</xsl:attribute>
754 <xsl:attribute name="id">css</xsl:attribute>
755 <xsl:attribute name="href"><xsl:value-of select="$html.stylesheet"/></xsl:attribute>
759 <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]">
760 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
761 <xsl:attribute name="id"> <xsl:value-of select="$epub.cover.id"/> </xsl:attribute>
762 <xsl:attribute name="href">
763 <xsl:value-of select="$epub.cover.html"/>
765 <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
770 <xsl:when test="$epub.embedded.fonts != '' and not(contains($epub.embedded.fonts, ','))">
771 <xsl:call-template name="embedded-font-item">
772 <xsl:with-param name="font.file" select="$epub.embedded.fonts"/> <!-- There is just one -->
775 <xsl:when test="$epub.embedded.fonts != ''">
776 <xsl:variable name="font.file.tokens" select="str:tokenize($epub.embedded.fonts, ',')"/>
777 <xsl:for-each select="exsl:node-set($font.file.tokens)">
778 <xsl:call-template name="embedded-font-item">
779 <xsl:with-param name="font.file" select="."/>
780 <xsl:with-param name="font.order" select="position()"/>
786 <!-- TODO: be nice to have a id="titlepage" here -->
787 <xsl:apply-templates select="//part|
788 //book[*[last()][self::bookinfo]]|
815 mode="opf.manifest"/>
816 <xsl:call-template name="opf.calloutlist"/>
820 <xsl:template name="opf.calloutlist">
821 <xsl:variable name="format">
822 <xsl:call-template name="guess-media-type">
823 <xsl:with-param name="ext" select="$callout.graphics.extension"/>
826 <xsl:if test="(//calloutlist|//co)">
827 <xsl:call-template name="opf.reference.callout">
828 <xsl:with-param name="conum" select="1"/>
829 <xsl:with-param name="format" select="$format"/>
834 <xsl:template name="opf.reference.callout">
835 <xsl:param name="conum"/>
836 <xsl:param name="format"/>
838 <xsl:variable name="filename" select="concat($callout.graphics.path, $conum, $callout.graphics.extension)"/>
840 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
841 <xsl:attribute name="id"> <xsl:value-of select="concat(generate-id(.), 'callout', $conum)"/> </xsl:attribute>
842 <xsl:attribute name="href"> <xsl:value-of select="$filename"/> </xsl:attribute>
843 <xsl:attribute name="media-type">
844 <xsl:value-of select="$format"/>
847 <xsl:if test="($conum < $callout.graphics.number.limit)">
848 <xsl:call-template name="opf.reference.callout">
849 <xsl:with-param name="conum" select="$conum + 1"/>
850 <xsl:with-param name="format" select="$format"/>
855 <xsl:template name="guess-media-type">
856 <xsl:param name="ext"></xsl:param>
858 <xsl:when test="contains($ext, '.gif')">
859 <xsl:text>image/gif</xsl:text>
861 <xsl:when test="contains($ext, 'GIF')">
862 <xsl:text>image/gif</xsl:text>
864 <xsl:when test="contains($ext, '.png')">
865 <xsl:text>image/png</xsl:text>
867 <xsl:when test="contains($ext, 'PNG')">
868 <xsl:text>image/png</xsl:text>
870 <xsl:when test="contains($ext, '.jpeg')">
871 <xsl:text>image/jpeg</xsl:text>
873 <xsl:when test="contains($ext, 'JPEG')">
874 <xsl:text>image/jpeg</xsl:text>
876 <xsl:when test="contains($ext, '.jpg')">
877 <xsl:text>image/jpeg</xsl:text>
879 <xsl:when test="contains($ext, 'JPG')">
880 <xsl:text>image/jpeg</xsl:text>
882 <xsl:when test="contains($ext, '.svg')">
883 <xsl:text>image/svg+xml</xsl:text>
885 <xsl:when test="contains($ext, 'SVG')">
886 <xsl:text>image/svg+xml</xsl:text>
890 <xsl:text></xsl:text>
895 <xsl:template match="mediaobject|
900 <xsl:variable name="olist" select="imageobject|imageobjectco |videoobject|audioobject |textobject"/>
902 <xsl:variable name="object.index">
903 <xsl:call-template name="select.mediaobject.index">
904 <xsl:with-param name="olist" select="$olist"/>
905 <xsl:with-param name="count" select="1"/>
909 <xsl:variable name="object" select="$olist[position() = $object.index]"/>
912 <xsl:when test="$object/descendant::imagedata[@format = 'GIF' or
913 @format = 'GIF87a' or
914 @format = 'GIF89a' or
919 <xsl:apply-templates select="$object[descendant::imagedata[@format = 'GIF' or
920 @format = 'GIF87a' or
921 @format = 'GIF89a' or
925 @format = 'SVG']][1]/imagedata"
926 mode="opf.manifest"/>
929 <xsl:apply-templates select="$object/imagedata[1]"
930 mode="opf.manifest"/>
935 <xsl:template match="cover/mediaobject|
936 mediaobject[@role='cover']"
939 <xsl:when test="imageobject[@role='front-large']">
940 <xsl:apply-templates select="imageobject[@role='front-large']/imagedata"
941 mode="opf.manifest"/>
944 <xsl:apply-templates select="imageobject/imagedata[1]"
945 mode="opf.manifest"/>
950 <xsl:template match="mediaobjectco"
952 <xsl:message>WARNING: mediaobjectco almost certainly will not render as expected in .epub!</xsl:message>
953 <xsl:apply-templates select="imageobjectco/imageobject/imagedata"
954 mode="opf.manifest"/>
957 <!-- 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?] -->
959 <!-- wish I had XSLT2 ...-->
960 <!-- TODO: priority a hack -->
961 <xsl:template match="graphic[not(@format)]|
962 inlinegraphic[not(@format)]|
963 imagedata[not(@format)]"
965 <xsl:variable name="filename">
967 <xsl:when test="contains(name(.), 'graphic')">
969 <xsl:when test="@entityref">
970 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
973 <xsl:apply-templates select="@fileref"/>
978 <xsl:call-template name="mediaobject.filename">
979 <xsl:with-param name="object" select=".."/>
984 <xsl:variable name="format">
985 <xsl:call-template name="guess-media-type">
986 <xsl:with-param name="ext" select="@fileref"/>
989 <xsl:variable name="fr" select="@fileref"/>
990 <xsl:if test="$format != ''">
991 <!-- only do this if we're the first file to match -->
992 <!-- TODO: Why can't this be simple equality?? (I couldn't get it to work) -->
993 <xsl:if test="generate-id(.) = generate-id(key('image-filerefs', $fr)[1])">
994 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
995 <xsl:attribute name="id">
997 <xsl:when test="ancestor::mediaobject[@role='cover'] and parent::*[@role='front-large']">
998 <xsl:value-of select="$epub.cover.image.id"/>
1000 <xsl:when test="ancestor::mediaobject[@role='cover'] and (count(ancestor::mediaobject//imageobject) = 1)">
1001 <xsl:value-of select="$epub.cover.image.id"/>
1003 <xsl:when test="ancestor::cover">
1004 <xsl:value-of select="$epub.cover.image.id"/>
1007 <xsl:value-of select="generate-id(.)"/>
1011 <xsl:attribute name="href"> <xsl:value-of select="$filename"/> </xsl:attribute>
1012 <xsl:attribute name="media-type">
1013 <xsl:value-of select="$format"/>
1020 <!-- Note: Selection of the first interesting imagedata is done in the select -->
1021 <xsl:template match="graphic[@format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or @format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or @format = 'SVG']|
1022 inlinegraphic[@format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or @format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or @format = 'SVG']|
1024 mode="opf.manifest">
1025 <xsl:variable name="filename">
1027 <xsl:when test="contains(name(.), 'graphic')">
1029 <xsl:when test="@entityref">
1030 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
1033 <xsl:apply-templates select="@fileref"/>
1038 <xsl:call-template name="mediaobject.filename">
1039 <xsl:with-param name="object" select=".."/>
1040 </xsl:call-template>
1044 <xsl:variable name="fr" select="@fileref"/>
1045 <!-- only do this if we're the first file to match -->
1046 <!-- TODO: Why can't this be simple equality?? (I couldn't get it to work) -->
1047 <xsl:if test="generate-id(.) = generate-id(key('image-filerefs', $fr)[1])">
1048 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
1049 <xsl:attribute name="id">
1051 <xsl:when test="ancestor::mediaobject[@role='cover'] and parent::*[@role='front-large']">
1052 <xsl:value-of select="$epub.cover.image.id"/>
1054 <xsl:when test="ancestor::mediaobject[@role='cover'] and (count(ancestor::mediaobject//imageobject) = 1)">
1055 <xsl:value-of select="$epub.cover.image.id"/>
1057 <xsl:when test="ancestor::cover">
1058 <xsl:value-of select="$epub.cover.image.id"/>
1061 <xsl:value-of select="generate-id(.)"/>
1065 <xsl:attribute name="href"> <xsl:value-of select="$filename"/> </xsl:attribute>
1066 <xsl:attribute name="media-type">
1067 <xsl:call-template name="guess-media-type">
1068 <xsl:with-param name="ext" select="@format"/>
1069 </xsl:call-template>
1075 <!-- Warning: While the test indicate this match list is accurate, it may
1076 need further tweaking to ensure _never_ dropping generated content (XHTML)
1077 from the manifest (OPF file) -->
1081 book[*[last()][self::bookinfo]]|
1102 mode="opf.manifest">
1103 <xsl:variable name="href">
1104 <xsl:call-template name="href.target.with.base.dir">
1105 <xsl:with-param name="context" select="/" />
1106 <!-- Generate links relative to the location of root file/toc.xml file -->
1107 </xsl:call-template>
1110 <xsl:variable name="id">
1111 <xsl:value-of select="generate-id(.)"/>
1114 <xsl:variable name="is.chunk">
1115 <xsl:call-template name="chunk">
1116 <xsl:with-param name="node" select="."/>
1117 </xsl:call-template>
1120 <xsl:if test="$is.chunk != 0">
1121 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
1122 <xsl:attribute name="id"> <xsl:value-of select="$id"/> </xsl:attribute>
1123 <xsl:attribute name="href"> <xsl:value-of select="$href"/> </xsl:attribute>
1124 <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
1129 <xsl:template match="text()" mode="ncx" />
1131 <xsl:template name="html.head">
1132 <xsl:param name="prev" select="/foo"/>
1133 <xsl:param name="next" select="/foo"/>
1134 <xsl:variable name="this" select="."/>
1135 <xsl:variable name="home" select="/*[1]"/>
1136 <xsl:variable name="up" select="parent::*"/>
1138 <head xmlns="http://www.w3.org/1999/xhtml">
1139 <xsl:call-template name="system.head.content"/>
1140 <xsl:call-template name="head.content"/>
1142 <xsl:call-template name="user.head.content"/>
1146 <!-- OVERRIDES xhtml-1_1/graphics.xsl -->
1147 <!-- we can't deal with no img/@alt, because it's required. Try grabbing a title before it instead (hopefully meaningful) -->
1148 <xsl:template name="process.image.attributes">
1149 <xsl:param name="alt"/>
1150 <xsl:param name="html.width"/>
1151 <xsl:param name="html.depth"/>
1152 <xsl:param name="longdesc"/>
1153 <xsl:param name="scale"/>
1154 <xsl:param name="scalefit"/>
1155 <xsl:param name="scaled.contentdepth"/>
1156 <xsl:param name="scaled.contentwidth"/>
1157 <xsl:param name="viewport"/>
1160 <xsl:when test="@contentwidth or @contentdepth">
1161 <!-- ignore @width/@depth, @scale, and @scalefit if specified -->
1162 <xsl:if test="@contentwidth and $scaled.contentwidth != ''">
1163 <xsl:attribute name="width">
1164 <xsl:value-of select="$scaled.contentwidth"/>
1167 <xsl:if test="@contentdepth and $scaled.contentdepth != ''">
1168 <xsl:attribute name="height">
1169 <xsl:value-of select="$scaled.contentdepth"/>
1174 <xsl:when test="number($scale) != 1.0">
1175 <!-- scaling is always uniform, so we only have to specify one dimension -->
1176 <!-- ignore @scalefit if specified -->
1177 <xsl:attribute name="width">
1178 <xsl:value-of select="$scaled.contentwidth"/>
1182 <xsl:when test="$scalefit != 0">
1184 <xsl:when test="contains($html.width, '%')">
1186 <xsl:when test="$viewport != 0">
1187 <!-- The *viewport* will be scaled, so use 100% here! -->
1188 <xsl:attribute name="width">
1189 <xsl:value-of select="'100%'"/>
1193 <xsl:attribute name="width">
1194 <xsl:value-of select="$html.width"/>
1200 <xsl:when test="contains($html.depth, '%')">
1201 <!-- HTML doesn't deal with this case very well...do nothing -->
1204 <xsl:when test="$scaled.contentwidth != '' and $html.width != '' and $scaled.contentdepth != '' and $html.depth != ''">
1205 <!-- scalefit should not be anamorphic; figure out which direction -->
1206 <!-- has the limiting scale factor and scale in that direction -->
1208 <xsl:when test="$html.width div $scaled.contentwidth > $html.depth div $scaled.contentdepth">
1209 <xsl:attribute name="height">
1210 <xsl:value-of select="$html.depth"/>
1214 <xsl:attribute name="width">
1215 <xsl:value-of select="$html.width"/>
1221 <xsl:when test="$scaled.contentwidth != '' and $html.width != ''">
1222 <xsl:attribute name="width">
1223 <xsl:value-of select="$html.width"/>
1227 <xsl:when test="$scaled.contentdepth != '' and $html.depth != ''">
1228 <xsl:attribute name="height">
1229 <xsl:value-of select="$html.depth"/>
1236 <!-- AN OVERRIDE -->
1237 <xsl:if test="not(@format ='SVG')">
1238 <xsl:attribute name="alt">
1240 <xsl:when test="$alt != ''">
1241 <xsl:value-of select="normalize-space($alt)"/>
1243 <xsl:when test="preceding::title[1]">
1244 <xsl:value-of select="normalize-space(preceding::title[1])"/>
1247 <xsl:text>(missing alt)</xsl:text>
1252 <!-- END OF OVERRIDE -->
1254 <xsl:if test="$longdesc != ''">
1255 <xsl:attribute name="longdesc">
1256 <xsl:value-of select="$longdesc"/>
1260 <xsl:if test="@align and $viewport = 0">
1261 <xsl:attribute name="style"><xsl:text>text-align: </xsl:text>
1263 <xsl:when test="@align = 'center'">middle</xsl:when>
1265 <xsl:value-of select="@align"/>
1272 <!-- OVERRIDES xhtml-1_1/chunk-common.xsl -->
1273 <!-- make a bibliography always a chunk -->
1274 <xsl:template name="chunk"
1276 <xsl:param name="node" select="."/>
1277 <!-- returns 1 if $node is a chunk -->
1279 <!-- ==================================================================== -->
1280 <!-- What's a chunk?
1285 bibliography ### NO LONGER TRUE in article or part or book
1289 glossary in article or part or book
1290 index in article or part or book
1295 sect{1,2,3,4,5} if position()>1 && depth < chunk.section.depth
1296 section if position()>1 && depth < chunk.section.depth
1300 <!-- ==================================================================== -->
1304 <xsl:text>chunk: </xsl:text>
1305 <xsl:value-of select="name($node)"/>
1306 <xsl:text>(</xsl:text>
1307 <xsl:value-of select="$node/@id"/>
1308 <xsl:text>)</xsl:text>
1309 <xsl:text> csd: </xsl:text>
1310 <xsl:value-of select="$chunk.section.depth"/>
1311 <xsl:text> cfs: </xsl:text>
1312 <xsl:value-of select="$chunk.first.sections"/>
1313 <xsl:text> ps: </xsl:text>
1314 <xsl:value-of select="count($node/parent::section)"/>
1315 <xsl:text> prs: </xsl:text>
1316 <xsl:value-of select="count($node/preceding-sibling::section)"/>
1321 <xsl:when test="not($node/parent::*)">1</xsl:when>
1323 <xsl:when test="local-name($node) = 'sect1' and $chunk.section.depth >= 1 and ($chunk.first.sections != 0 or count($node/preceding-sibling::sect1) > 0)">
1324 <xsl:text>1</xsl:text>
1326 <xsl:when test="local-name($node) = 'sect2' and $chunk.section.depth >= 2 and ($chunk.first.sections != 0 or count($node/preceding-sibling::sect2) > 0)">
1327 <xsl:call-template name="chunk">
1328 <xsl:with-param name="node" select="$node/parent::*"/>
1329 </xsl:call-template>
1331 <xsl:when test="local-name($node) = 'sect3' and $chunk.section.depth >= 3 and ($chunk.first.sections != 0 or count($node/preceding-sibling::sect3) > 0)">
1332 <xsl:call-template name="chunk">
1333 <xsl:with-param name="node" select="$node/parent::*"/>
1334 </xsl:call-template>
1336 <xsl:when test="local-name($node) = 'sect4' and $chunk.section.depth >= 4 and ($chunk.first.sections != 0 or count($node/preceding-sibling::sect4) > 0)">
1337 <xsl:call-template name="chunk">
1338 <xsl:with-param name="node" select="$node/parent::*"/>
1339 </xsl:call-template>
1341 <xsl:when test="local-name($node) = 'sect5' and $chunk.section.depth >= 5 and ($chunk.first.sections != 0 or count($node/preceding-sibling::sect5) > 0)">
1342 <xsl:call-template name="chunk">
1343 <xsl:with-param name="node" select="$node/parent::*"/>
1344 </xsl:call-template>
1346 <xsl:when test="local-name($node) = 'section' and $chunk.section.depth >= count($node/ancestor::section)+1 and ($chunk.first.sections != 0 or count($node/preceding-sibling::section) > 0)">
1347 <xsl:call-template name="chunk">
1348 <xsl:with-param name="node" select="$node/parent::*"/>
1349 </xsl:call-template>
1352 <xsl:when test="local-name($node)='preface'">1</xsl:when>
1353 <xsl:when test="local-name($node)='chapter'">1</xsl:when>
1354 <xsl:when test="local-name($node)='appendix'">1</xsl:when>
1355 <xsl:when test="local-name($node)='article'">1</xsl:when>
1356 <xsl:when test="local-name($node)='part'">1</xsl:when>
1357 <xsl:when test="local-name($node)='reference'">1</xsl:when>
1358 <xsl:when test="local-name($node)='refentry'">1</xsl:when>
1359 <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>
1360 <!-- AN OVERRIDE -->
1361 <xsl:when test="local-name($node)='bibliography'">1</xsl:when>
1362 <!-- END OF OVERRIDE -->
1363 <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>
1364 <xsl:when test="local-name($node)='colophon'">1</xsl:when>
1365 <xsl:when test="local-name($node)='book'">1</xsl:when>
1366 <xsl:when test="local-name($node)='set'">1</xsl:when>
1367 <xsl:when test="local-name($node)='setindex'">1</xsl:when>
1368 <xsl:when test="local-name($node)='legalnotice' and $generate.legalnotice.link != 0">1</xsl:when>
1369 <xsl:otherwise>0</xsl:otherwise>
1373 <!-- OVERRIDES xhtml-1_1/chunk-code.xsl -->
1374 <!-- Add chunking for bibliography as root element -->
1375 <!-- AN OVERRIDE -->
1376 <xsl:template match="set|
1391 <!-- END OF OVERRIDE -->
1393 <xsl:when test="$onechunk != 0 and parent::*">
1394 <xsl:apply-imports/>
1397 <xsl:call-template name="process-chunk-element"/>
1402 <!-- OVERRIDES xhtml-1_1/graphics.xsl -->
1403 <!-- Do _NOT_ output any xlink garbage, so if you don't have
1404 processor with extensions, you're screwed and we're terminating -->
1405 <xsl:template match="inlinegraphic">
1406 <xsl:variable name="filename">
1408 <xsl:when test="@entityref">
1409 <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
1412 <xsl:apply-templates select="@fileref"/>
1417 <xsl:call-template name="anchor"/>
1420 <xsl:when test="@format='linespecific'">
1422 <xsl:when test="$use.extensions != '0' and $textinsert.extension != '0'">
1424 <xsl:when test="element-available('stext:insertfile')">
1425 <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
1427 <xsl:when test="element-available('xtext:insertfile')">
1428 <xtext:insertfile href="{$filename}"/>
1431 <xsl:message terminate="yes">
1432 <xsl:text>No insertfile extension available.</xsl:text>
1438 <!-- AN OVERRIDE -->
1439 <xsl:message terminate="yes">
1440 <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>
1442 <!-- END OF OVERRIDE -->
1447 <xsl:call-template name="process.image"/>
1452 <xsl:template name="cover">
1453 <xsl:apply-templates select="/*/*[contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]"/>
1456 <xsl:template match="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]">
1457 <xsl:call-template name="write.chunk">
1458 <xsl:with-param name="filename">
1459 <xsl:value-of select="$epub.cover.filename" />
1461 <xsl:with-param name="method" select="'xml'" />
1462 <xsl:with-param name="encoding" select="'utf-8'" />
1463 <xsl:with-param name="indent" select="'no'" />
1464 <xsl:with-param name="quiet" select="$chunk.quietly" />
1465 <xsl:with-param name="content">
1466 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="html">
1467 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="head">
1468 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="title">Cover</xsl:element>
1469 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="style">
1470 <xsl:attribute name="type">text/css</xsl:attribute>
1471 <!-- Help the cover image scale nicely in the CSS then apply a max-width to look better in Adobe Digital Editions -->
1472 <xsl:text> img { max-width: 100%; }</xsl:text>
1475 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="body">
1476 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="div">
1477 <xsl:attribute name="id">
1478 <xsl:value-of select="$epub.cover.image.id"/>
1481 <xsl:when test="imageobject[@role='front-large']">
1482 <xsl:apply-templates select="imageobject[@role='front-large']"/>
1485 <xsl:apply-templates select="imageobject[1]"/>
1489 <!-- If this is defined as an explicit cover page, then process
1490 any remaining text -->
1491 <xsl:if test="ancestor::cover">
1492 <xsl:apply-templates select="ancestor::cover/para"/>
1497 </xsl:call-template>
1500 <xsl:template name="cover-svg">
1501 <xsl:param name="node"/>
1504 <xsl:template name="toc-href">
1505 <xsl:param name="node" select="."/>
1506 <xsl:apply-templates select="$node" mode="recursive-chunk-filename">
1507 <xsl:with-param name="recursive" select="true()"/>
1508 </xsl:apply-templates>
1509 <xsl:text>-toc</xsl:text>
1510 <xsl:value-of select="$html.ext"/>
1513 <xsl:template match="bibliodiv[title]" mode="label.markup">
1516 <xsl:template match="token" mode="opf.manifest.font">
1517 <xsl:call-template name="embedded-font-item">
1518 <xsl:with-param name="font.file" select="."/>
1519 </xsl:call-template>
1522 <xsl:template name="embedded-font-item">
1523 <xsl:param name="font.file"/>
1524 <xsl:param name="font.order" select="1"/>
1526 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
1527 <xsl:attribute name="id">
1528 <xsl:value-of select="concat('epub.embedded.font.', $font.order)"/>
1530 <xsl:attribute name="href"><xsl:value-of select="$font.file"/></xsl:attribute>
1532 <xsl:when test="contains($font.file, 'otf')">
1533 <xsl:attribute name="media-type">font/opentype</xsl:attribute>
1537 <xsl:text>WARNING: OpenType fonts should be supplied! (</xsl:text>
1538 <xsl:value-of select="$font.file"/>
1539 <xsl:text>)</xsl:text>
1546 <!-- Change section.heading to improve SEO on generated HTML by doing heading levels
1547 "correctly". SEO rules are sometimes silly silly, but this does actually create
1548 a semantic improvement.
1549 Note: This template needs to be manually maintained outside of the html/sections.xsl
1550 code, so make sure important changes get reintegrated. -->
1551 <xsl:template name="section.heading">
1552 <xsl:param name="section" select="."/>
1553 <xsl:param name="level" select="1"/>
1554 <xsl:param name="allow-anchors" select="1"/>
1555 <xsl:param name="title"/>
1556 <xsl:param name="class" select="'title'"/>
1558 <xsl:variable name="id">
1560 <!-- Make sure the subtitle doesn't get the same id as the title -->
1561 <xsl:when test="self::subtitle">
1562 <xsl:call-template name="object.id">
1563 <xsl:with-param name="object" select="."/>
1564 </xsl:call-template>
1566 <!-- if title is in an *info wrapper, get the grandparent -->
1567 <xsl:when test="contains(local-name(..), 'info')">
1568 <xsl:call-template name="object.id">
1569 <xsl:with-param name="object" select="../.."/>
1570 </xsl:call-template>
1573 <xsl:call-template name="object.id">
1574 <xsl:with-param name="object" select=".."/>
1575 </xsl:call-template>
1580 <!-- For SEO, we try to actually ensure we *always* output one and only one h1,
1581 so unlike the regular stylesheets, we don't add one to the section level and
1582 we get the right behavior because of chunking. -->
1583 <xsl:variable name="hlevel">
1585 <!-- highest valid HTML H level is H6; so anything nested deeper
1586 than 7 levels down just becomes H6 -->
1587 <xsl:when test="$level > 6">6</xsl:when>
1589 <xsl:value-of select="$level"/>
1593 <xsl:element name="h{$hlevel}" namespace="http://www.w3.org/1999/xhtml">
1594 <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
1595 <xsl:if test="$css.decoration != '0'">
1596 <xsl:if test="$hlevel<3">
1597 <xsl:attribute name="style">clear: both</xsl:attribute>
1600 <xsl:if test="$allow-anchors != 0 and $generate.id.attributes = 0">
1601 <xsl:call-template name="anchor">
1602 <xsl:with-param name="node" select="$section"/>
1603 <xsl:with-param name="conditional" select="0"/>
1604 </xsl:call-template>
1606 <xsl:if test="$generate.id.attributes != 0 and not(local-name(.) = 'appendix')">
1607 <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
1609 <xsl:copy-of select="$title"/>
1613 <!-- ==================================================================== -->
1615 <xsl:template match="bridgehead">
1616 <xsl:variable name="container" select="(ancestor::appendix |ancestor::article |ancestor::bibliography |ancestor::chapter |ancestor::glossary |ancestor::glossdiv |ancestor::index |ancestor::partintro |ancestor::preface |ancestor::refsect1 |ancestor::refsect2 |ancestor::refsect3 |ancestor::sect1 |ancestor::sect2 |ancestor::sect3 |ancestor::sect4 |ancestor::sect5 |ancestor::section |ancestor::setindex |ancestor::simplesect)[last()]"/>
1618 <xsl:variable name="clevel">
1620 <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>
1621 <xsl:when test="local-name($container) = 'glossdiv'">
1622 <xsl:value-of select="count(ancestor::glossdiv)+1"/>
1624 <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'">
1625 <xsl:variable name="slevel">
1626 <xsl:call-template name="section.level">
1627 <xsl:with-param name="node" select="$container"/>
1628 </xsl:call-template>
1630 <xsl:value-of select="$slevel + 1"/>
1632 <xsl:otherwise>1</xsl:otherwise>
1636 <!-- HTML H level is one higher than section level -->
1637 <xsl:variable name="hlevel">
1639 <xsl:when test="@renderas = 'sect1'">1</xsl:when>
1640 <xsl:when test="@renderas = 'sect2'">2</xsl:when>
1641 <xsl:when test="@renderas = 'sect3'">3</xsl:when>
1642 <xsl:when test="@renderas = 'sect4'">4</xsl:when>
1643 <xsl:when test="@renderas = 'sect5'">5</xsl:when>
1645 <xsl:value-of select="$clevel + 1"/>
1650 <xsl:element name="h{$hlevel}" namespace="http://www.w3.org/1999/xhtml">
1651 <xsl:call-template name="anchor">
1652 <xsl:with-param name="conditional" select="0"/>
1653 </xsl:call-template>
1654 <xsl:apply-templates/>
1658 <!-- SEO customization #2 -->
1659 <xsl:template name="component.title">
1660 <xsl:param name="node" select="."/>
1662 <xsl:variable name="level">
1664 <xsl:when test="ancestor::section">
1665 <xsl:value-of select="count(ancestor::section)+1"/>
1667 <xsl:when test="ancestor::sect5">6</xsl:when>
1668 <xsl:when test="ancestor::sect4">5</xsl:when>
1669 <xsl:when test="ancestor::sect3">4</xsl:when>
1670 <xsl:when test="ancestor::sect2">3</xsl:when>
1671 <xsl:when test="ancestor::sect1">2</xsl:when>
1672 <xsl:otherwise>1</xsl:otherwise>
1676 <xsl:element name="h{$level}" namespace="http://www.w3.org/1999/xhtml">
1677 <xsl:attribute name="class">title</xsl:attribute>
1678 <xsl:if test="$generate.id.attributes = 0">
1679 <xsl:call-template name="anchor">
1680 <xsl:with-param name="node" select="$node"/>
1681 <xsl:with-param name="conditional" select="0"/>
1682 </xsl:call-template>
1684 <xsl:apply-templates select="$node" mode="object.title.markup">
1685 <xsl:with-param name="allow-anchors" select="1"/>
1686 </xsl:apply-templates>