1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE xsl:stylesheet [
3 <!ENTITY uppercase "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'">
4 <!ENTITY lowercase "'abcdefghijklmnopqrstuvwxyz'">
8 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
9 xmlns:exsl="http://exslt.org/common"
10 xmlns:set="http://exslt.org/sets"
11 xmlns="http://www.w3.org/1999/xhtml"
12 xmlns:epub="http://www.idpf.org/2007/ops"
13 xmlns:m="http://www.w3.org/1998/Math/MathML"
14 xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon"
15 xmlns:ssml="http://www.w3.org/2001/10/synthesis"
16 xmlns:svg="http://www.w3.org/2000/svg"
17 xmlns:opf="http://www.idpf.org/2007/opf"
18 xmlns:dc="http://purl.org/dc/elements/1.1/"
19 xmlns:cf="http://docbook.sourceforge.net/xmlns/chunkfast/1.0"
20 xmlns:date="http://exslt.org/dates-and-times"
21 xmlns:dcterms="http://purl.org/dc/terms/"
22 xmlns:ncx="http://www.daisy.org/z3986/2005/ncx/"
23 xmlns:db="http://docbook.org/ns/docbook"
24 xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
25 xmlns:str="http://exslt.org/strings"
26 xmlns:xtext="xalan://com.nwalsh.xalan.Text"
28 extension-element-prefixes="stext xtext"
29 exclude-result-prefixes="#default cf date db dc dcterms epub exsl m ncx opf pls set ssml stext str svg xtext"
32 <!-- $Id: epub3-element-mods.xsl,v 1.1 2011-09-16 21:43:45 bobs Exp $ -->
34 <xsl:import href="titlepage.templates.xsl"/>
37 <xsl:key name="image-filerefs" match="graphic|inlinegraphic|imagedata" use="@fileref"/>
40 <!--==============================================================-->
41 <!-- DocBook XSL Parameter settings -->
42 <!--==============================================================-->
43 <!-- separate file for toc -->
44 <xsl:param name="chunk.tocs.and.lots" select="1"/>
45 <xsl:param name="toc.section.depth" select="2"/>
46 <xsl:param name="generate.toc">
47 book toc,title,figure,table,example,equation
48 article toc,title,figure,table,example,equation
50 <xsl:param name="generate.manifest" select="0"/>
51 <xsl:param name="manifest.in.base.dir" select="1"/>
52 <xsl:param name="base.dir" select="'OEBPS/'"/>
53 <xsl:param name="index.links.to.section" select="0"/>
55 <!-- Epub does not yet support external links -->
56 <xsl:param name="activate.external.olinks" select="0"/>
58 <!-- Turning this on crashes ADE, which is unbelievably awesome -->
59 <xsl:param name="formal.object.break.after">0</xsl:param>
61 <xsl:param name="callout.graphics" select="1"/>
62 <xsl:param name="callout.graphics.extension">.png</xsl:param>
63 <xsl:param name="callout.graphics.number.limit" select="15"/>
64 <xsl:param name="callout.graphics.path" select="'images/callouts/'"/>
65 <xsl:param name="show.comments" select="0"/>
67 <!-- no navigation in .epub -->
68 <xsl:param name="suppress.navigation" select="'1'"/>
70 <!-- EPUB3: use ol lists in table of contents -->
71 <xsl:param name="toc.list.type">ol</xsl:param>
72 <xsl:param name="autotoc.label.in.hyperlink" select="1"/>
74 <xsl:param name="css.decoration" select="1"/>
75 <!-- generate the css file from a source file -->
76 <xsl:param name="make.clean.html" select="1"/>
77 <!-- specify the default epub3 stylesheet -->
78 <xsl:param name="docbook.css.source">docbook-epub.css.xml</xsl:param>
79 <!-- for custom CSS, use the custom.css.source param -->
80 <xsl:param name="custom.css.source"></xsl:param>
82 <!--==============================================================-->
83 <!-- New EPUB3 Parameters -->
84 <!--==============================================================-->
85 <xsl:param name="epub.version">3.0</xsl:param>
86 <!-- optional ncx for backwards compatibility -->
87 <xsl:param name="epub.include.ncx" select="1"/>
88 <xsl:param name="epub.ncx.depth">4</xsl:param> <!-- Not functional until http://code.google.com/p/epubcheck/issues/detail?id=70 is resolved -->
89 <!-- currently optional duplicate dcterms properties, may be required in future -->
90 <xsl:param name="epub.include.metadata.dcterms" select="1"/>
91 <!-- optional guide element for backwards compatibility -->
92 <xsl:param name="epub.include.guide" select="1"/>
93 <!-- some dc: currently required, to be replaced in future version -->
94 <xsl:param name="epub.include.metadata.dc.elements" select="1"/>
95 <!-- Some dc: elements will remain optional according to the spec -->
96 <xsl:param name="epub.include.optional.metadata.dc.elements" select="1"/>
97 <xsl:param name="epub.autolabel" select="0"/>
99 name="epub.vocabulary.profile.content">http://www.idpf.org/epub/30/profile/content/</xsl:param>
101 name="epub.vocabulary.profile.package">http://www.idpf.org/epub/30/profile/package/</xsl:param>
102 <xsl:param name="epub.output.epub.types" select="1"/>
103 <xsl:param name="epub.oebps.dir" select="'OEBPS'"/>
104 <xsl:param name="epub.metainf.dir" select="'META-INF/'"/>
105 <xsl:param name="epub.ncx.filename" select="'toc.ncx'"/>
106 <xsl:param name="epub.mimetype.filename" select="'mimetype'"/>
107 <xsl:param name="epub.mimetype.value" select="'application/epub+zip'"/>
108 <xsl:param name="epub.container.filename" select="'container.xml'"/>
109 <xsl:param name="epub.package.filename" select="'package.opf'"/>
110 <xsl:param name="epub.cover.filename" select="concat('cover', $html.ext)"/>
111 <xsl:param name="epub.cover.linear" select="0" />
113 <!-- names of id attributes used in package files -->
114 <xsl:param name="epub.meta.identifier.id">meta-identifier</xsl:param>
115 <xsl:param name="epub.dc.identifier.id">pub-identifier</xsl:param>
116 <xsl:param name="epub.meta.title.id">meta-title</xsl:param>
117 <xsl:param name="epub.dc.title.id">pub-title</xsl:param>
118 <xsl:param name="epub.meta.language.id">meta-language</xsl:param>
119 <xsl:param name="epub.dc.language.id">pub-language</xsl:param>
120 <xsl:param name="epub.meta.creator.id">meta-creator</xsl:param>
121 <xsl:param name="epub.dc.creator.id">pub-creator</xsl:param>
122 <xsl:param name="epub.ncx.toc.id">ncxtoc</xsl:param>
123 <xsl:param name="epub.ncx.manifest.id">ncx</xsl:param>
124 <xsl:param name="epub.ncx.mediatype">application/x-dtbncx+xml</xsl:param>
125 <xsl:param name="epub.xhtml.mediatype">application/xhtml+xml</xsl:param>
126 <xsl:param name="epub.html.toc.id">htmltoc</xsl:param>
127 <xsl:param name="epub.cover.filename.id" select="'cover'"/>
128 <xsl:param name="epub.cover.image.id" select="'cover-image'"/>
130 <xsl:param name="epub.embedded.fonts"></xsl:param>
131 <xsl:param name="epub.namespace">http://www.idpf.org/2007/ops</xsl:param>
132 <xsl:param name="opf.namespace">http://www.idpf.org/2007/opf</xsl:param>
133 <xsl:param name="ncx.namespace">http://www.daisy.org/z3986/2005/ncx/</xsl:param>
134 <xsl:param name="dc.namespace">http://purl.org/dc/elements/1.1/</xsl:param>
135 <!-- prefix generated ids in package elements so they differ from content ids -->
136 <xsl:param name="epub.package.id.prefix">id-</xsl:param>
137 <!-- editor is either a creator or contributor -->
138 <xsl:param name="editor.property">contributor</xsl:param>
140 <!-- Generate full output path -->
141 <xsl:param name="epub.package.dir" select="concat($chunk.base.dir, '../')"/>
143 <xsl:param name="epub.ncx.pathname"
144 select="concat($chunk.base.dir, $epub.ncx.filename)"/>
145 <xsl:param name="epub.container.pathname"
146 select="concat($epub.package.dir, $epub.metainf.dir,
147 $epub.container.filename)"/>
148 <xsl:param name="epub.package.pathname"
149 select="concat($chunk.base.dir, $epub.package.filename)"/>
150 <xsl:param name="epub.cover.pathname"
151 select="concat($chunk.base.dir, $epub.cover.filename)"/>
152 <xsl:param name="epub.mimetype.pathname"
153 select="concat($epub.package.dir, $epub.mimetype.filename)"/>
155 <xsl:param name="kindle.extensions" select="0"/>
157 <!--==============================================================-->
158 <!-- Internal variables used for computing certain metadata -->
159 <!--==============================================================-->
160 <xsl:variable name="epub3.chunk.hierarchy">
161 <xsl:apply-templates select="/*" mode="find.chunks"/>
164 <xsl:variable name="chunkset" select="exsl:node-set($epub3.chunk.hierarchy)//cf:div"/>
166 <!--==============================================================-->
167 <!-- Template customizations -->
168 <!--==============================================================-->
170 <!-- This is used only by ncx piece -->
171 <xsl:variable name="root.is.a.chunk">
173 <xsl:when test="/*[not(self::book)][not(sect1) or not(section)]">
174 <xsl:text>1</xsl:text>
176 <xsl:when test="/book[*[last()][self::bookinfo]]|book[bookinfo]">
177 <xsl:text>1</xsl:text>
179 <xsl:when test="/book[*[last()][self::info]]|book[info]">
180 <xsl:text>1</xsl:text>
182 <xsl:when test="/bibliography">
183 <xsl:text>1</xsl:text>
186 <xsl:text>0</xsl:text>
191 <!-- EPUB3: Add generation of epub publication files -->
192 <xsl:template match="*" mode="process.root">
193 <xsl:variable name="doc" select="self::*"/>
195 <xsl:call-template name="user.preroot"/>
196 <xsl:call-template name="root.messages"/>
200 <xsl:call-template name="system.head.content">
201 <xsl:with-param name="node" select="$doc"/>
203 <xsl:call-template name="head.content">
204 <xsl:with-param name="node" select="$doc"/>
206 <xsl:call-template name="user.head.content">
207 <xsl:with-param name="node" select="$doc"/>
211 <xsl:call-template name="body.attributes"/>
212 <xsl:call-template name="user.header.content">
213 <xsl:with-param name="node" select="$doc"/>
215 <xsl:apply-templates select="."/>
216 <xsl:call-template name="user.footer.content">
217 <xsl:with-param name="node" select="$doc"/>
221 <xsl:value-of select="$html.append"/>
223 <!-- Generate any css files only once, not once per chunk -->
224 <xsl:call-template name="generate.css.files"/>
226 <xsl:call-template name="generate.epub.files"/>
230 <xsl:template name="generate.epub.files">
231 <!-- Generate epub3 files -->
233 <xsl:text>Generating EPUB package files.</xsl:text>
236 <xsl:apply-templates select="." mode="opf"/>
237 <xsl:apply-templates select="." mode="container"/>
238 <xsl:call-template name="mimetype"/>
239 <xsl:if test="$epub.include.ncx != 0">
240 <xsl:call-template name="ncx"/>
244 <!-- Generate the package file -->
245 <xsl:template match="*" mode="opf">
247 <xsl:variable name="lang">
248 <xsl:call-template name="l10n.language"/>
251 <xsl:variable name="content">
252 <!-- use xsl:element so output does not have a namespace prefix -->
253 <xsl:element name="package" namespace="{$opf.namespace}">
254 <!-- Add the package namespaces at the top -->
255 <xsl:call-template name="add.package.namespaces"/>
257 <xsl:attribute name="version">
258 <xsl:value-of select="$epub.version"/>
260 <xsl:attribute name="xml:lang">
261 <xsl:value-of select="$lang"/>
263 <!-- No profile att in 2011-09-06 spec
264 <xsl:attribute name="profile">
265 <xsl:value-of select="$epub.vocabulary.profile.package"/>
268 <xsl:attribute name="unique-identifier">
269 <xsl:value-of select="$epub.dc.identifier.id"/>
273 <xsl:call-template name="package.metadata"/>
274 <xsl:call-template name="package.manifest"/>
275 <xsl:call-template name="package.spine"/>
277 <xsl:if test="$epub.include.guide != 0">
278 <xsl:call-template name="package.guide"/>
284 <xsl:call-template name="write.chunk">
285 <xsl:with-param name="filename">
286 <xsl:value-of select="$epub.package.pathname" />
288 <xsl:with-param name="content" select="$content"/>
289 <xsl:with-param name="method" select="'xml'" />
290 <xsl:with-param name="encoding" select="'utf-8'" />
291 <xsl:with-param name="indent" select="'yes'" />
292 <xsl:with-param name="quiet" select="$chunk.quietly" />
293 <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
294 <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
298 <xsl:template name="package.metadata">
300 <xsl:element name="metadata" namespace="{$opf.namespace}">
302 <xsl:call-template name="metadata.identifier"/>
303 <xsl:call-template name="metadata.title"/>
304 <xsl:call-template name="metadata.language"/>
305 <xsl:call-template name="metadata.modified"/>
306 <xsl:call-template name="metadata.cover"/>
307 <xsl:call-template name="metadata.other.info"/>
312 <xsl:template name="doc.title">
313 <xsl:apply-templates select="." mode="title.markup"/>
316 <xsl:template name="metadata.identifier">
317 <xsl:variable name="package.id.value">
318 <xsl:call-template name="package-identifier"/>
321 <xsl:if test="$epub.include.metadata.dc.elements != 0">
322 <!-- dc:identifier element -->
324 <xsl:attribute name="id">
325 <xsl:value-of select="$epub.dc.identifier.id"/>
328 <xsl:attribute name="prefer">
329 <xsl:value-of select="$epub.meta.identifier.id"/>
332 <xsl:copy-of select="$package.id.value"/>
336 <xsl:if test="$epub.include.metadata.dcterms != 0">
337 <!-- equivalent meta identifier element -->
338 <xsl:element name="meta" namespace="{$opf.namespace}">
339 <xsl:attribute name="id">
340 <xsl:value-of select="$epub.meta.identifier.id"/>
342 <xsl:attribute name="property">dcterms:identifier</xsl:attribute>
343 <xsl:copy-of select="$package.id.value"/>
348 <xsl:template name="metadata.title">
349 <xsl:variable name="doc.title">
350 <xsl:call-template name="doc.title"/>
353 <xsl:if test="$epub.include.metadata.dc.elements != 0">
355 <xsl:attribute name="id">
356 <xsl:value-of select="$epub.dc.title.id"/>
359 <xsl:attribute name="prefer">
360 <xsl:value-of select="$epub.meta.title.id"/>
363 <xsl:value-of select="normalize-space($doc.title)"/>
367 <xsl:if test="$epub.include.metadata.dcterms != 0">
368 <!-- equivalent meta title element -->
369 <xsl:element name="meta" namespace="{$opf.namespace}">
370 <xsl:attribute name="property">dcterms:title</xsl:attribute>
371 <xsl:attribute name="id">
372 <xsl:value-of select="$epub.meta.title.id"/>
374 <xsl:value-of select="normalize-space($doc.title)"/>
379 <xsl:template name="metadata.language">
380 <xsl:variable name="lang">
381 <xsl:call-template name="l10n.language"/>
384 <xsl:if test="$epub.include.metadata.dc.elements != 0">
386 <xsl:if test="$kindle.extensions = 0">
387 <xsl:attribute name="id">
388 <xsl:value-of select="$epub.dc.language.id"/>
391 <xsl:value-of select="$lang"/>
395 <xsl:if test="$epub.include.metadata.dcterms != 0">
396 <!-- equivalent meta lang element -->
397 <xsl:element name="meta" namespace="{$opf.namespace}">
398 <xsl:attribute name="property">dcterms:language</xsl:attribute>
399 <xsl:attribute name="id">
400 <xsl:value-of select="$epub.meta.language.id"/>
402 <xsl:value-of select="$lang"/>
407 <xsl:template name="metadata.modified">
408 <xsl:variable name="local.datetime" select="date:date-time()"/>
409 <xsl:variable name="utc.datetime">
410 <xsl:call-template name="convert.date.to.utc">
411 <xsl:with-param name="date" select="$local.datetime"/>
415 <xsl:when test="string-length($utc.datetime) != 0">
416 <xsl:element name="meta" namespace="{$opf.namespace}">
417 <xsl:attribute name="property">dcterms:modified</xsl:attribute>
418 <xsl:value-of select="$utc.datetime"/>
420 <xsl:comment>The preceding date value is actually local time (not UTC) in UTC format because there is no function in XSLT 1.0 to generate a correct UTC time</xsl:comment>
423 <xsl:message terminate="yes">
424 <xsl:text>ERROR: no last-modified date value could be determined, </xsl:text>
425 <xsl:text>so cannot output required meta element with </xsl:text>
426 <xsl:text>dcterms:modified attribute. Exiting.</xsl:text>
432 <xsl:template name="convert.date.to.utc">
433 <xsl:param name="date" select="''"/>
434 <!-- input format is YYYY-MM-DDTHH:MM:SS-X:00
435 where -X:00 is the offset from UTC. -->
437 <!-- output format is YYYY-MM-DDTHH:MM:SSZ with no offset -->
438 <!-- FIX ME: Not so easy without a proper UTC date function. -->
439 <!-- Currently it just converts the local time to this format, which is
440 not the correct UTC time. -->
441 <xsl:value-of select="concat(substring($date,1,19), 'Z')"/>
444 <!-- This cover meta element used by kindlegen, at least -->
445 <xsl:template name="metadata.cover">
446 <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
447 <xsl:variable name="cover.image"
448 select="$info//mediaobject[@role='cover' or ancestor::cover]"/>
450 <xsl:if test="$cover.image">
451 <xsl:element name="meta" namespace="{$opf.namespace}">
452 <xsl:attribute name="content">
453 <xsl:value-of select="$epub.cover.image.id"/>
455 <xsl:attribute name="name">cover</xsl:attribute>
460 <xsl:template name="metadata.other.info">
461 <!-- Take info relative to selected root element -->
462 <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
464 <xsl:apply-templates select="$info/*" mode="opf.metadata"/>
467 <xsl:template match="*" mode="opf.metadata">
468 <!-- default is no output -->
471 <xsl:template match="authorgroup" mode="opf.metadata">
472 <xsl:apply-templates select="*" mode="opf.metadata"/>
475 <xsl:template match="author|corpauthor" mode="opf.metadata">
476 <xsl:variable name="n">
478 <xsl:when test="self::corpauthor">
479 <xsl:apply-templates/>
481 <xsl:when test="org/orgname">
482 <xsl:apply-templates select="org/orgname"/>
484 <xsl:when test="orgname">
485 <xsl:apply-templates select="orgname"/>
488 <xsl:call-template name="person.name">
489 <xsl:with-param name="node" select="."/>
495 <xsl:if test="string-length($n) != 0">
496 <xsl:element name="meta" namespace="{$opf.namespace}">
497 <xsl:attribute name="id">
498 <xsl:value-of select="concat($epub.meta.creator.id, position())"/>
500 <xsl:attribute name="property">dcterms:creator</xsl:attribute>
501 <xsl:value-of select="normalize-space(string($n))"/>
504 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
506 <xsl:attribute name="id">
507 <xsl:value-of select="concat($epub.dc.creator.id, position())"/>
509 <xsl:value-of select="$n"/>
515 <xsl:template match="editor" mode="opf.metadata">
516 <xsl:variable name="n">
518 <xsl:when test="orgname">
519 <xsl:apply-templates select="orgname"/>
522 <xsl:call-template name="person.name">
523 <xsl:with-param name="node" select="."/>
529 <xsl:variable name="name">
531 <xsl:when test="string-length($editor.property) != 0">
532 <xsl:value-of select="$editor.property"/>
535 <xsl:text>contributor</xsl:text>
540 <xsl:element name="meta" namespace="{$opf.namespace}">
541 <xsl:attribute name="property">
542 <xsl:text>dcterms:</xsl:text>
543 <xsl:value-of select="$name"/>
545 <xsl:value-of select="normalize-space($n)"/>
548 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
550 <xsl:when test="$name = 'creator'">
552 <xsl:value-of select="normalize-space($n)"/>
555 <xsl:when test="$name = 'contributor'">
557 <xsl:value-of select="normalize-space($n)"/>
561 <xsl:element namespace="{$dc.namespace}" name="{$name}">
562 <xsl:value-of select="normalize-space($n)"/>
570 <xsl:template match="corpcredit" mode="opf.metadata">
571 <xsl:element name="meta" namespace="{$opf.namespace}">
572 <xsl:attribute name="property">dcterms:contributor</xsl:attribute>
573 <xsl:value-of select="normalize-space(.)"/>
576 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
578 <xsl:value-of select="normalize-space(.)"/>
583 <xsl:template match="collab|othercredit" mode="opf.metadata">
584 <xsl:variable name="content">
586 <xsl:when test="collabname">
587 <xsl:apply-templates select="collabname"/>
589 <xsl:when test="org/orgname">
590 <xsl:apply-templates select="org/orgname"/>
592 <xsl:when test="orgname">
593 <xsl:apply-templates select="orgname"/>
595 <xsl:when test="personname|firstname|surname|othername">
596 <xsl:call-template name="person.name"/>
599 <xsl:value-of select="."/>
604 <xsl:element name="meta" namespace="{$opf.namespace}">
605 <xsl:attribute name="property">dcterms:contributor</xsl:attribute>
606 <xsl:value-of select="normalize-space($content)"/>
609 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
611 <xsl:value-of select="normalize-space($content)"/>
617 <xsl:template match="date|pubdate" mode="opf.metadata">
618 <xsl:variable name="date">
619 <xsl:call-template name="format.meta.date">
620 <xsl:with-param name="string" select="normalize-space(.)"/>
624 <xsl:if test="string-length($date) != 0">
625 <xsl:element name="meta" namespace="{$opf.namespace}">
626 <xsl:attribute name="property">dcterms:date</xsl:attribute>
627 <xsl:value-of select="$date"/>
630 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
632 <xsl:value-of select="$date"/>
639 <!-- EPUB3 meta date should be of the form:
640 YYYY, YYYY-MM or YYYY-MM-DD -->
641 <xsl:template name="format.meta.date">
642 <xsl:param name="string" select="''"/>
643 <xsl:param name="node" select="."/>
645 <!-- FIXME: this needs further work, so just check the
646 string format and return the date string for now -->
647 <xsl:variable name="normalized"
648 select="translate($string, '0123456789', '##########')"/>
650 <xsl:variable name="date.ok">
652 <xsl:when test="string-length($string) = 4 and
653 $normalized = '####'">1</xsl:when>
654 <xsl:when test="string-length($string) = 7 and
655 $normalized = '####-##'">1</xsl:when>
656 <xsl:when test="string-length($string) = 10 and
657 $normalized = '####-##-##'">1</xsl:when>
658 <xsl:when test="string-length($string) = 10 and
659 $normalized = '####-##-##'">1</xsl:when>
660 <xsl:otherwise>0</xsl:otherwise>
664 <xsl:if test="$date.ok = 0">
666 <xsl:text>WARNING: wrong metadata date format: '</xsl:text>
667 <xsl:value-of select="$string"/>
668 <xsl:text>' in element </xsl:text>
669 <xsl:value-of select="local-name($node/..)"/>
670 <xsl:text>/</xsl:text>
671 <xsl:value-of select="local-name($node)"/>
672 <xsl:text>. It must be in one of these forms: </xsl:text>
673 <xsl:text>YYYY, YYYY-MM, or YYYY-MM-DD.</xsl:text>
677 <!-- return the string anyway -->
678 <xsl:value-of select="$string"/>
683 <!-- Space separate the compontents of the abstract (dropping the inline markup, sadly) -->
684 <xsl:template match="abstract" mode="opf.metadata">
685 <xsl:variable name="content">
686 <xsl:for-each select="formalpara|para|simpara|title">
688 <xsl:when test="self::formalpara">
689 <xsl:value-of select="normalize-space(string(title))"/>
690 <xsl:text>: </xsl:text>
691 <xsl:value-of select="normalize-space(string(para))"/>
694 <xsl:value-of select="normalize-space(string(.))"/>
697 <xsl:if test="self::title">
698 <xsl:text>:</xsl:text>
700 <xsl:if test="not(position() = last())">
701 <xsl:text> </xsl:text>
706 <xsl:element name="meta" namespace="{$opf.namespace}">
707 <xsl:attribute name="property">dcterms:description</xsl:attribute>
708 <xsl:copy-of select="$content"/>
711 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
713 <xsl:copy-of select="$content"/>
718 <xsl:template match="subjectset" mode="opf.metadata">
719 <xsl:apply-templates select="subject/subjectterm" mode="opf.metadata"/>
722 <xsl:template match="subjectterm" mode="opf.metadata">
723 <xsl:element name="meta" namespace="{$opf.namespace}">
724 <xsl:attribute name="property">dcterms:subject</xsl:attribute>
725 <xsl:value-of select="normalize-space(string(.))"/>
728 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
730 <xsl:value-of select="normalize-space(string(.))"/>
735 <xsl:template match="keywordset" mode="opf.metadata">
736 <xsl:apply-templates select="keyword" mode="opf.metadata"/>
739 <xsl:template match="keyword" mode="opf.metadata">
740 <xsl:element name="meta" namespace="{$opf.namespace}">
741 <xsl:attribute name="property">dcterms:subject</xsl:attribute>
742 <xsl:value-of select="normalize-space(string(.))"/>
745 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
747 <xsl:value-of select="normalize-space(string(.))"/>
752 <xsl:template match="publisher" mode="opf.metadata">
753 <xsl:apply-templates select="publishername" mode="opf.metadata"/>
756 <xsl:template match="publishername" mode="opf.metadata">
757 <xsl:element name="meta" namespace="{$opf.namespace}">
758 <xsl:attribute name="property">dcterms:publisher</xsl:attribute>
759 <xsl:value-of select="normalize-space(string(.))"/>
762 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
764 <xsl:value-of select="normalize-space(string(.))"/>
769 <xsl:template match="bibliocoverage" mode="opf.metadata">
770 <xsl:element name="meta" namespace="{$opf.namespace}">
771 <xsl:attribute name="property">dcterms:coverage</xsl:attribute>
772 <xsl:value-of select="normalize-space(string(.))"/>
775 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
777 <xsl:value-of select="normalize-space(string(.))"/>
782 <xsl:template match="bibliorelation" mode="opf.metadata">
783 <xsl:element name="meta" namespace="{$opf.namespace}">
784 <xsl:attribute name="property">dcterms:relation</xsl:attribute>
785 <xsl:value-of select="normalize-space(string(.))"/>
788 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
790 <xsl:value-of select="normalize-space(string(.))"/>
795 <xsl:template match="bibliosource" mode="opf.metadata">
796 <xsl:element name="meta" namespace="{$opf.namespace}">
797 <xsl:attribute name="property">dcterms:source</xsl:attribute>
798 <xsl:value-of select="normalize-space(string(.))"/>
801 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
803 <xsl:value-of select="normalize-space(string(.))"/>
808 <xsl:template match="copyright" mode="opf.metadata">
809 <xsl:variable name="copyright.date">
810 <xsl:call-template name="copyright.years">
811 <xsl:with-param name="years" select="year"/>
812 <xsl:with-param name="print.ranges" select="$make.year.ranges"/>
813 <xsl:with-param name="single.year.ranges" select="$make.single.year.ranges"/>
817 <!-- if no docbook date element, use copyright year for single date metadata -->
818 <xsl:if test="not(../date)">
819 <xsl:variable name="date.content">
820 <xsl:call-template name="format.meta.date">
821 <xsl:with-param name="string">
822 <xsl:call-template name="copyright.years">
823 <xsl:with-param name="years" select="year[last()]"/>
824 <xsl:with-param name="print.ranges" select="0"/>
825 <xsl:with-param name="single.year.ranges" select="0"/>
830 <xsl:element name="meta" namespace="{$opf.namespace}">
831 <xsl:attribute name="property">dcterms:date</xsl:attribute>
832 <xsl:copy-of select="$date.content"/>
834 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
836 <xsl:copy-of select="$date.content"/>
841 <xsl:variable name="rights.content">
842 <xsl:call-template name="gentext">
843 <xsl:with-param name="key" select="'Copyright'"/>
845 <xsl:call-template name="gentext.space"/>
846 <xsl:text>©</xsl:text>
847 <xsl:call-template name="gentext.space"/>
848 <xsl:value-of select="$copyright.date"/>
849 <xsl:call-template name="gentext.space"/>
850 <xsl:apply-templates select="holder" mode="titlepage.mode"/>
853 <xsl:element name="meta" namespace="{$opf.namespace}">
854 <xsl:attribute name="property">dcterms:rights</xsl:attribute>
855 <xsl:copy-of select="$rights.content"/>
857 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
859 <xsl:copy-of select="$rights.content"/>
863 <xsl:element name="meta" namespace="{$opf.namespace}">
864 <xsl:attribute name="property">dcterms:rightsHolder</xsl:attribute>
865 <xsl:apply-templates select="holder" mode="titlepage.mode"/>
869 <xsl:template name="package.guide">
871 <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
873 <xsl:variable name="toc.params">
874 <xsl:call-template name="find.path.params">
875 <xsl:with-param name="node" select="."/>
876 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
880 <xsl:if test="contains($toc.params, 'toc') or
882 $info//mediaobject[@role='cover' or ancestor::cover]">
883 <xsl:element namespace="{$opf.namespace}" name="guide">
884 <xsl:if test="$info/cover or
885 $info//mediaobject[@role='cover' or ancestor::cover]">
886 <xsl:element namespace="{$opf.namespace}" name="reference">
887 <xsl:attribute name="href">
888 <xsl:value-of select="$epub.cover.filename" />
890 <xsl:attribute name="type">cover</xsl:attribute>
891 <xsl:attribute name="title">Cover</xsl:attribute>
895 <xsl:if test="contains($toc.params, 'toc')">
896 <xsl:element namespace="{$opf.namespace}" name="reference">
897 <xsl:attribute name="href">
898 <xsl:call-template name="toc-href">
899 <xsl:with-param name="node" select="."/>
902 <xsl:attribute name="type">toc</xsl:attribute>
903 <xsl:attribute name="title">Table of Contents</xsl:attribute>
911 <xsl:template name="package-identifier">
913 <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
916 <xsl:when test="$info/biblioid">
917 <xsl:if test="$info/biblioid[1][@class = 'doi' or
922 <xsl:text>urn:</xsl:text>
923 <xsl:value-of select="$info/biblioid[1]/@class"/>
924 <xsl:text>:</xsl:text>
926 <xsl:value-of select="normalize-space($info/biblioid[1])"/>
928 <xsl:when test="$info/isbn">
929 <xsl:text>urn:isbn:</xsl:text>
930 <xsl:value-of select="$info/isbn[1]"/>
932 <xsl:when test="$info/issn">
933 <xsl:text>urn:issn:</xsl:text>
934 <xsl:value-of select="$info/issn[1]"/>
938 <xsl:when test="$info/invpartnumber">
939 <xsl:value-of select="$info/invpartnumber[1]"/>
941 <xsl:when test="$info/issuenum">
942 <xsl:value-of select="$info/issuenum[1]"/>
944 <xsl:when test="$info/productnumber">
945 <xsl:value-of select="$info/productnumber[1]"/>
947 <xsl:when test="$info/seriesvolnums">
948 <xsl:value-of select="$info/seriesvolnums[1]"/>
950 <xsl:when test="$info/volumenum">
951 <xsl:value-of select="$info/volumenum[1]"/>
954 <xsl:when test="$info/pubsnumber">
955 <xsl:value-of select="$info/pubsnumber[1]"/>
958 <xsl:text>_</xsl:text>
960 <xsl:when test="@id">
961 <xsl:value-of select="@id"/>
963 <xsl:when test="@xml:id">
964 <xsl:value-of select="@xml:id"/>
967 <!-- TODO: Do UUIDs here -->
968 <xsl:value-of select="generate-id(.)"/>
975 <!-- EPUB3: add epub:type attribute where appropriate -->
976 <xsl:template match="*" mode="common.html.attributes">
977 <xsl:param name="class" select="local-name(.)"/>
978 <xsl:param name="inherit" select="0"/>
979 <xsl:call-template name="generate.html.lang"/>
980 <xsl:call-template name="dir">
981 <xsl:with-param name="inherit" select="$inherit"/>
983 <xsl:apply-templates select="." mode="class.attribute">
984 <xsl:with-param name="class" select="$class"/>
985 </xsl:apply-templates>
986 <xsl:call-template name="generate.html.title"/>
987 <xsl:apply-templates select="." mode="epub.type"/>
990 <xsl:template match="*" mode="epub.type" priority="-1"/>
992 <xsl:template match="chapter
1008 |part" mode="epub.type">
1009 <xsl:variable name="type" select="local-name()"/>
1011 <xsl:if test="$epub.output.epub.types != 0">
1012 <xsl:attribute name="epub:type">
1013 <xsl:value-of select="$type"/>
1018 <xsl:template match="section[parent::chapter] | sect1" mode="epub.type">
1019 <xsl:if test="$epub.output.epub.types != 0">
1020 <xsl:attribute name="epub:type">subchapter</xsl:attribute>
1024 <xsl:template match="section[not(parent::chapter)] |
1029 sect6" mode="epub.type">
1030 <xsl:if test="$epub.output.epub.types != 0">
1031 <xsl:attribute name="epub:type">division</xsl:attribute>
1035 <xsl:template match="note|tip|caution|important" mode="epub.type">
1036 <xsl:if test="$epub.output.epub.types != 0">
1037 <xsl:attribute name="epub:type">notice</xsl:attribute>
1041 <xsl:template match="orderedlist|itemizedlist|variablelist|simplelist" mode="epub.type">
1042 <xsl:if test="$epub.output.epub.types != 0">
1043 <xsl:attribute name="epub:type">list</xsl:attribute>
1047 <xsl:template match="listitem" mode="epub.type">
1048 <xsl:if test="$epub.output.epub.types != 0">
1049 <xsl:attribute name="epub:type">list-item</xsl:attribute>
1053 <!-- EPUB3: to add attributes to root output element -->
1054 <xsl:template name="root.attributes">
1055 <!-- collect and output all namespace declarations -->
1056 <xsl:call-template name="all.namespaces"/>
1059 <xsl:template name="all.namespaces">
1060 <!-- add the epub3 namespaces to the top output element -->
1061 <xsl:variable name="temp">
1069 <xsl:variable name="nodes" select="exsl:node-set($temp)"/>
1070 <xsl:for-each select="$nodes//*/namespace::*">
1071 <xsl:copy-of select="."/>
1076 <xsl:template name="add.package.namespaces">
1077 <!-- add the epub3 package namespaces to the top output element -->
1078 <xsl:variable name="temp">
1083 <xsl:variable name="nodes" select="exsl:node-set($temp)"/>
1084 <xsl:for-each select="$nodes//*[local-name(.) ='foo']/namespace::*">
1085 <xsl:if test="contains(., 'purl.org')">
1086 <xsl:copy-of select="."/>
1093 <xsl:template name="footnotes.attributes">
1094 <xsl:if test="$epub.output.epub.types != 0">
1095 <xsl:attribute name="epub:type">footnotes</xsl:attribute>
1099 <xsl:template name="package.manifest">
1100 <xsl:element name="manifest" namespace="{$opf.namespace}">
1101 <xsl:if test="$epub.include.ncx != 0">
1102 <xsl:call-template name="manifest.ncx"/>
1104 <xsl:call-template name="manifest.fonts"/>
1105 <xsl:call-template name="manifest.toc"/>
1106 <xsl:call-template name="manifest.css"/>
1107 <xsl:call-template name="manifest.cover"/>
1108 <xsl:call-template name="manifest.other.items"/>
1109 <xsl:call-template name="manifest.content.items"/>
1110 <xsl:call-template name="user.manifest.items"/>
1114 <xsl:template name="user.manifest.items"/>
1116 <xsl:template name="manifest.css">
1117 <xsl:if test="$html.stylesheet != ''">
1118 <xsl:call-template name="css.item">
1119 <xsl:with-param name="stylesheets" select="$html.stylesheet"/>
1120 </xsl:call-template>
1122 <xsl:if test="string-length($docbook.css.source) != 0">
1123 <xsl:variable name="dfilename">
1124 <xsl:call-template name="css.output.filename">
1125 <xsl:with-param name="src" select="$docbook.css.source"/>
1126 </xsl:call-template>
1128 <xsl:element namespace="{$opf.namespace}" name="item">
1129 <xsl:attribute name="media-type">text/css</xsl:attribute>
1130 <xsl:attribute name="id">docbook-css</xsl:attribute>
1131 <xsl:attribute name="href">
1132 <xsl:value-of select="$dfilename"/>
1136 <xsl:if test="string-length($custom.css.source) != 0">
1137 <xsl:variable name="cfilename">
1138 <xsl:call-template name="css.output.filename">
1139 <xsl:with-param name="src" select="$custom.css.source"/>
1140 </xsl:call-template>
1142 <xsl:element namespace="{$opf.namespace}" name="item">
1143 <xsl:attribute name="media-type">text/css</xsl:attribute>
1144 <xsl:attribute name="id">custom-css</xsl:attribute>
1145 <xsl:attribute name="href">
1146 <xsl:value-of select="$cfilename"/>
1152 <xsl:template name="css.item">
1153 <xsl:param name="stylesheets" select="''"/>
1154 <xsl:param name="count" select="1"/>
1157 <xsl:when test="contains($stylesheets, ' ')">
1158 <xsl:variable name="css.filename" select="substring-before($stylesheets, ' ')"/>
1159 <xsl:if test="$css.filename != ''">
1160 <xsl:element namespace="{$opf.namespace}" name="item">
1161 <xsl:attribute name="media-type">text/css</xsl:attribute>
1162 <xsl:attribute name="id">
1163 <xsl:text>html-css</xsl:text>
1164 <xsl:if test="$count > 1">
1165 <xsl:value-of select="$count"/>
1168 <xsl:attribute name="href">
1169 <xsl:value-of select="$css.filename"/>
1174 <xsl:call-template name="css.item">
1175 <xsl:with-param name="stylesheets" select="substring-after($stylesheets, ' ')"/>
1176 <xsl:with-param name="count" select="$count + 1"/>
1177 </xsl:call-template>
1180 <xsl:if test="$stylesheets != ''">
1181 <xsl:element namespace="{$opf.namespace}" name="item">
1182 <xsl:attribute name="media-type">text/css</xsl:attribute>
1183 <xsl:attribute name="id">
1184 <xsl:text>html-css</xsl:text>
1185 <xsl:if test="$count > 1">
1186 <xsl:value-of select="$count"/>
1189 <xsl:attribute name="href">
1190 <xsl:value-of select="$stylesheets"/>
1198 <xsl:template name="manifest.ncx">
1199 <xsl:element name="item" namespace="{$opf.namespace}">
1200 <xsl:attribute name="id">
1201 <xsl:value-of select="$epub.ncx.manifest.id"/>
1203 <xsl:attribute name="href">
1204 <xsl:value-of select="$epub.ncx.filename"/>
1206 <xsl:attribute name="media-type">
1207 <xsl:value-of select="$epub.ncx.mediatype"/>
1212 <xsl:template name="manifest.fonts"/>
1214 <!--Misc items in the manifest based on content -->
1215 <xsl:template name="manifest.other.items">
1219 <xsl:template name="manifest.cover">
1220 <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
1221 <xsl:variable name="cover.image"
1222 select="$info//mediaobject[@role='cover' or ancestor::cover]"/>
1224 <xsl:if test="$cover.image">
1226 <!-- generate the manifest link to that page -->
1227 <xsl:variable name="olist" select="$cover.image/imageobject|$cover.image/imageobjectco
1228 |$cover.image/videoobject|$cover.image/audioobject
1229 |$cover.image/textobject"/>
1231 <xsl:variable name="object.index">
1232 <xsl:call-template name="select.mediaobject.index">
1233 <xsl:with-param name="olist" select="$olist"/>
1234 <xsl:with-param name="count" select="1"/>
1235 </xsl:call-template>
1238 <xsl:variable name="object" select="$olist[position() = $object.index]"/>
1240 <xsl:variable name="output_filename">
1241 <xsl:call-template name="mediaobject.filename">
1242 <xsl:with-param name="object" select="$object"/>
1243 </xsl:call-template>
1246 <xsl:variable name="image.filename">
1247 <xsl:if test="$img.src.path != '' and
1248 not(starts-with($output_filename, '/')) and
1249 not(contains($output_filename, '://'))">
1250 <xsl:value-of select="$img.src.path"/>
1252 <xsl:value-of select="$output_filename"/>
1254 <xsl:variable name="image.extension">
1255 <xsl:call-template name="filename-extension">
1256 <xsl:with-param name="filename" select="$image.filename"/>
1257 </xsl:call-template>
1260 <xsl:variable name="image.type">
1261 <xsl:call-template name="graphic.format.content-type">
1262 <xsl:with-param name="format" select="translate($image.extension,
1263 &lowercase;, &uppercase;)"/>
1264 </xsl:call-template>
1267 <!-- Reference to cover html file -->
1268 <xsl:element namespace="{$opf.namespace}" name="item">
1269 <xsl:attribute name="id">
1270 <xsl:value-of select="$epub.cover.filename.id"/>
1272 <xsl:attribute name="href">
1273 <xsl:value-of select="$epub.cover.filename"/>
1275 <xsl:attribute name="media-type">
1276 <xsl:value-of select="$epub.xhtml.mediatype"/>
1280 <!-- special item with property="cover-image" -->
1281 <xsl:element namespace="{$opf.namespace}" name="item">
1282 <xsl:attribute name="id">
1283 <xsl:value-of select="$epub.cover.image.id"/>
1285 <xsl:attribute name="properties">cover-image</xsl:attribute>
1286 <xsl:attribute name="href">
1287 <xsl:value-of select="$image.filename"/>
1289 <xsl:if test="$image.type">
1290 <xsl:attribute name="media-type">
1291 <xsl:value-of select="$image.type"/>
1296 <!-- And generate the cover html file -->
1297 <xsl:apply-templates select="$cover.image"/>
1302 <xsl:template name="manifest.toc">
1303 <xsl:variable name="toc.params">
1304 <xsl:call-template name="find.path.params">
1305 <xsl:with-param name="node" select="."/>
1306 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
1307 </xsl:call-template>
1310 <xsl:if test="contains($toc.params, 'toc')">
1311 <xsl:element namespace="{$opf.namespace}" name="item">
1312 <xsl:attribute name="id">
1313 <xsl:value-of select="$epub.html.toc.id"/>
1315 <xsl:attribute name="properties">nav</xsl:attribute>
1316 <xsl:attribute name="media-type">
1317 <xsl:value-of select="$epub.xhtml.mediatype"/>
1319 <xsl:attribute name="href">
1320 <xsl:call-template name="toc-href">
1321 <xsl:with-param name="node" select="."/>
1322 </xsl:call-template>
1328 <xsl:template name="toc-href">
1329 <xsl:param name="node" select="."/>
1331 <xsl:apply-templates select="$node" mode="recursive-chunk-filename">
1332 <xsl:with-param name="recursive" select="true()"/>
1333 </xsl:apply-templates>
1334 <xsl:text>-toc</xsl:text>
1335 <xsl:value-of select="$html.ext"/>
1338 <xsl:template match="*" mode="recursive-chunk-filename">
1339 <!-- placeholder for real template in chunking stylesheet -->
1340 <xsl:value-of select="concat(local-name(.), '-', generate-id(.))"/>
1343 <xsl:template name="manifest.content.items">
1344 <xsl:apply-templates select="." mode="package.manifest"/>
1345 <xsl:call-template name="manifest.images"/>
1348 <xsl:template match="text()" mode="package.manifest"/>
1350 <xsl:template match="mediaobject|mediaobjectco|inlinemediaobject" priority="1"
1351 mode="package.manifest">
1352 <!-- These are handled out of line so a unique list is created
1353 to remove duplicate references -->
1356 <xsl:template match="*" mode="package.manifest">
1358 <xsl:variable name="is.chunk">
1359 <xsl:call-template name="chunk">
1360 <xsl:with-param name="node" select="."/>
1361 </xsl:call-template>
1364 <xsl:if test="$is.chunk != 0">
1365 <xsl:variable name="href">
1366 <xsl:call-template name="href.target.with.base.dir">
1367 <xsl:with-param name="context" select="/"/>
1368 </xsl:call-template>
1371 <xsl:variable name="id" select="concat($epub.package.id.prefix, generate-id())"/>
1373 <xsl:variable name="properties.set">
1374 <xsl:call-template name="svg.property"/>
1375 <xsl:text> </xsl:text>
1376 <xsl:call-template name="mathml.property"/>
1379 <xsl:variable name="properties" select="normalize-space($properties.set)"/>
1381 <xsl:element namespace="{$opf.namespace}" name="item">
1382 <xsl:attribute name="id">
1383 <xsl:value-of select="$id"/>
1385 <xsl:attribute name="href">
1386 <xsl:value-of select="$href"/>
1388 <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
1389 <xsl:if test="string-length($properties) != 0">
1390 <xsl:attribute name="properties">
1391 <xsl:value-of select="$properties"/>
1396 <xsl:apply-templates mode="package.manifest"/>
1400 <xsl:template name="svg.property">
1401 <xsl:param name="this.chunk" select="."/>
1403 <xsl:variable name="genid" select="generate-id($this.chunk)"/>
1405 <!-- get the chunkfast div element for this chunk -->
1406 <xsl:variable name="div" select="$chunkset[@id=$genid or @xml:id=$genid]"/>
1408 <!-- get the chunkfast div element the next chunk -->
1409 <xsl:variable name="nextdiv"
1410 select="($div/following-sibling::cf:div|
1411 $div/following::cf:div|
1414 <!-- get the element corresponding to the next chunk -->
1415 <xsl:variable name="next.chunk" select="key('genid', ($nextdiv/@id|$nextdiv/@xml:id)[1])"/>
1418 <xsl:when test="$next.chunk">
1419 <xsl:variable name="this.imagedata"
1420 select="$this.chunk//mediaobject"/>
1421 <xsl:variable name="before.next"
1422 select="$next.chunk/preceding::mediaobject"/>
1424 <!-- select for an SVG imagedata in the intersection of them -->
1425 <xsl:variable name="mediaobject.set"
1426 select="$this.imagedata[count(.|$before.next) = count($before.next)]"/>
1427 <xsl:variable name="svg.imagedata">
1428 <xsl:for-each select="$mediaobject.set">
1429 <xsl:variable name="olist" select="imageobject[not(@role = 'poster')] |
1431 <xsl:variable name="mediaobject.index">
1432 <xsl:call-template name="select.mediaobject.index">
1433 <xsl:with-param name="olist" select="$olist"/>
1434 </xsl:call-template>
1436 <xsl:variable name="object" select="$olist[position() = $mediaobject.index]"/>
1437 <xsl:if test="$object/imagedata[contains(
1438 substring(@fileref, string-length(@fileref)-3,4), '.svg')]">
1439 <xsl:text>svg</xsl:text>
1444 <xsl:if test="contains($svg.imagedata, 'svg')">
1445 <xsl:text>svg</xsl:text>
1449 <xsl:variable name="mediaobject.set"
1450 select="$this.chunk//mediaobject"/>
1451 <xsl:variable name="svg.imagedata">
1452 <xsl:for-each select="$mediaobject.set">
1453 <xsl:variable name="olist" select="imageobject[not(@role = 'poster')] |
1455 <xsl:variable name="mediaobject.index">
1456 <xsl:call-template name="select.mediaobject.index">
1457 <xsl:with-param name="olist" select="$olist"/>
1458 </xsl:call-template>
1460 <xsl:variable name="object" select="$olist[position() = $mediaobject.index]"/>
1461 <xsl:if test="$object/imagedata[contains(
1462 substring(@fileref, string-length(@fileref)-3,4), '.svg')]">
1463 <xsl:text>svg</xsl:text>
1468 <xsl:if test="contains($svg.imagedata, 'svg')">
1469 <xsl:text>svg</xsl:text>
1476 <xsl:template name="mathml.property">
1477 <xsl:param name="this.chunk" select="."/>
1479 <xsl:variable name="genid" select="generate-id($this.chunk)"/>
1481 <!-- get the chunkfast div element for this chunk -->
1482 <xsl:variable name="div" select="$chunkset[@id=$genid or @xml:id=$genid]"/>
1484 <!-- get the chunkfast div element the next chunk -->
1485 <xsl:variable name="nextdiv"
1486 select="($div/following-sibling::cf:div|
1487 $div/following::cf:div|
1490 <!-- get the element corresponding to the next chunk -->
1491 <xsl:variable name="next.chunk" select="key('genid', ($nextdiv/@id|$nextdiv/@xml:id)[1])"/>
1493 <xsl:variable name="this.math"
1494 select="$this.chunk//m:*"/>
1495 <xsl:variable name="before.next"
1496 select="$next.chunk/preceding::m:*"/>
1498 <!-- select for an SVG imagedata in the intersection of them -->
1499 <xsl:variable name="intersection"
1500 select="$this.math[count(.|$before.next) = count($before.next)]"/>
1502 <xsl:if test="count($intersection) != 0">
1503 <xsl:text>mathml</xsl:text>
1507 <xsl:template name="manifest.image.item">
1510 <!-- Need a uniqued list of images -->
1511 <xsl:template name="manifest.images">
1512 <xsl:message>Generating image list ...</xsl:message>
1513 <xsl:variable name="imagelist">
1515 <xsl:when test="$rootid != ''">
1516 <xsl:apply-templates select="key('id', $rootid)" mode="enumerate-images"/>
1519 <xsl:apply-templates select="/" mode="enumerate-images"/>
1525 <xsl:when test="$exsl.node.set.available != 0 and
1526 function-available('set:distinct')">
1527 <xsl:for-each select="set:distinct(exsl:node-set($imagelist)/*)">
1528 <xsl:if test="string-length(tmp-href) != 0">
1529 <!-- convert the child elements to attributes -->
1530 <xsl:element name="item" namespace="{$opf.namespace}">
1531 <xsl:attribute name="id">
1532 <xsl:value-of select="generate-id()"/>
1534 <xsl:attribute name="href">
1535 <xsl:value-of select="tmp-href"/>
1537 <xsl:attribute name="media-type">
1538 <xsl:value-of select="media-type"/>
1544 <xsl:when test="$exsl.node.set.available != 0">
1545 <xsl:for-each select="exsl:node-set($imagelist)/*">
1546 <xsl:element name="item" namespace="{$opf.namespace}">
1547 <xsl:attribute name="id">
1548 <xsl:value-of select="generate-id()"/>
1550 <xsl:attribute name="href">
1551 <xsl:value-of select="tmp-href"/>
1553 <xsl:attribute name="media-type">
1554 <xsl:value-of select="media-type"/>
1560 <xsl:message terminate="yes">
1561 <xsl:text>ERROR: cannot process images list without </xsl:text>
1562 <xsl:text>exsl:node-set() function</xsl:text>
1564 <!-- cannot do this without node-set() -->
1570 <xsl:template match="*" mode="enumerate-images">
1571 <xsl:apply-templates mode="enumerate-images"/>
1574 <xsl:template match="text()" mode="enumerate-images"/>
1576 <xsl:template match="graphic|inlinegraphic[@format!='linespecific']"
1577 mode="enumerate-images">
1580 <!-- cover image handled separates to give it an extra property attribute -->
1581 <xsl:template match="mediaobject[@role='cover' or ancestor::cover]"
1582 mode="enumerate-images"/>
1584 <xsl:template match="mediaobject|inlinemediaobject" mode="enumerate-images">
1586 <xsl:variable name="olist"
1587 select="imageobject[not(@role = 'poster')]
1593 <xsl:variable name="object.index">
1594 <xsl:call-template name="select.mediaobject.index">
1595 <xsl:with-param name="olist" select="$olist"/>
1596 <xsl:with-param name="count" select="1"/>
1597 </xsl:call-template>
1600 <xsl:variable name="object" select="$olist[position() = $object.index]"/>
1602 <xsl:apply-templates select="$object" mode="enumerate-images"/>
1604 <!-- also include a poster image if present -->
1605 <xsl:apply-templates select="imageobject[@role = 'poster']" mode="enumerate-images"/>
1609 <xsl:template match="imageobject|videoobject|audioobject" mode="enumerate-images">
1610 <xsl:param name="object" select="."/>
1612 <xsl:if test="$object">
1613 <xsl:variable name="output_filename">
1614 <xsl:call-template name="mediaobject.filename">
1615 <xsl:with-param name="object" select="$object"/>
1616 </xsl:call-template>
1619 <xsl:variable name="image.filename">
1620 <xsl:if test="$img.src.path != '' and
1621 not(starts-with($output_filename, '/')) and
1622 not(contains($output_filename, '://'))">
1623 <xsl:value-of select="$img.src.path"/>
1625 <xsl:value-of select="$output_filename"/>
1628 <xsl:variable name="image.extension">
1629 <xsl:call-template name="filename-extension">
1630 <xsl:with-param name="filename" select="$image.filename"/>
1631 </xsl:call-template>
1634 <xsl:variable name="image.type">
1635 <xsl:call-template name="graphic.format.content-type">
1636 <xsl:with-param name="format" select="translate($image.extension,
1637 &lowercase;, &uppercase;)"/>
1638 </xsl:call-template>
1641 <xsl:element name="tmp-filename" namespace="">
1642 <xsl:element name="tmp-href" namespace="">
1643 <xsl:value-of select="$image.filename"/>
1645 <xsl:element name="media-type" namespace="">
1646 <xsl:value-of select="$image.type"/>
1653 <!-- Add in the generated images -->
1654 <xsl:template match="note|caution|warning|important|tip" mode="enumerate-images">
1655 <xsl:if test="$admon.graphics != 0">
1656 <xsl:variable name="image.filename">
1657 <xsl:call-template name="admon.graphic"/>
1660 <xsl:variable name="image.type">
1661 <xsl:call-template name="graphic.format.content-type">
1662 <xsl:with-param name="format" select="translate(
1663 substring-after($admon.graphics.extension,'.'),
1664 &lowercase;, &uppercase;)"/>
1665 </xsl:call-template>
1668 <xsl:element name="tmp-filename" namespace="">
1669 <xsl:element name="tmp-href" namespace="">
1670 <xsl:value-of select="$image.filename"/>
1672 <xsl:element name="media-type" namespace="">
1673 <xsl:value-of select="$image.type"/>
1680 <xsl:template match="callout" mode="enumerate-images">
1681 <!-- process arearefs to get name of callout bug image files -->
1682 <xsl:if test="$callout.graphics != 0">
1683 <xsl:variable name="arearefs">
1684 <xsl:call-template name="callout.arearefs">
1685 <xsl:with-param name="arearefs" select="@arearefs"/>
1686 </xsl:call-template>
1689 <xsl:variable name="nodes" select="exsl:node-set($arearefs)"/>
1691 <xsl:for-each select="$nodes//*[@src]">
1692 <xsl:variable name="image.filename" select="@src"/>
1694 <xsl:variable name="image.type">
1695 <xsl:call-template name="graphic.format.content-type">
1696 <xsl:with-param name="format" select="translate(
1697 substring-after($callout.graphics.extension,'.'),
1698 &lowercase;, &uppercase;)"/>
1699 </xsl:call-template>
1702 <xsl:element name="tmp-filename" namespace="">
1703 <xsl:element name="tmp-href" namespace="">
1704 <xsl:value-of select="$image.filename"/>
1706 <xsl:element name="media-type" namespace="">
1707 <xsl:value-of select="$image.type"/>
1715 <xsl:template match="co" mode="enumerate-images">
1716 <!-- process co to get name of callout bug image file -->
1717 <xsl:if test="$callout.graphics != 0">
1718 <xsl:variable name="result">
1719 <xsl:apply-templates select="." mode="callout-bug"/>
1722 <xsl:variable name="nodes" select="exsl:node-set($result)"/>
1724 <xsl:for-each select="$nodes//*[@src]">
1725 <xsl:variable name="image.filename" select="@src"/>
1727 <xsl:variable name="image.type">
1728 <xsl:call-template name="graphic.format.content-type">
1729 <xsl:with-param name="format" select="translate(
1730 substring-after($callout.graphics.extension,'.'),
1731 &lowercase;, &uppercase;)"/>
1732 </xsl:call-template>
1735 <xsl:element name="tmp-filename" namespace="">
1736 <xsl:element name="tmp-href" namespace="">
1737 <xsl:value-of select="$image.filename"/>
1739 <xsl:element name="media-type" namespace="">
1740 <xsl:value-of select="$image.type"/>
1749 <!-- ======================================================== -->
1750 <!-- NCX templates are for backwards compatibility with EPUB2 -->
1751 <!-- ======================================================== -->
1753 <xsl:template name="ncx">
1754 <xsl:message>Generating NCX file ...</xsl:message>
1755 <xsl:call-template name="write.chunk">
1756 <xsl:with-param name="filename">
1757 <xsl:value-of select="$epub.ncx.pathname" />
1759 <xsl:with-param name="method" select="'xml'" />
1760 <xsl:with-param name="encoding" select="'utf-8'" />
1761 <xsl:with-param name="indent" select="'no'" />
1762 <xsl:with-param name="quiet" select="$chunk.quietly" />
1763 <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
1764 <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
1765 <xsl:with-param name="content">
1766 <xsl:element name="ncx" namespace="{$ncx.namespace}">
1767 <xsl:attribute name="version">2005-1</xsl:attribute>
1769 <!-- Via Martin Goerner: On covers: the IDPF2.0 standard unfortunately does not have a provision for
1770 covers. We had to add one and we did so in conjunction with the IDPF and
1771 various publishers. The tag chosen to define the covers is:
1772 <meta name="cover" content="-reference to a manifest item-">
1773 Then, we also added a bit of logic to get rid cleanly of the HTML cover
1774 people usually add because the logical cover is not specced by the IDPF. So,
1775 if the HTML cover item is marked linear="no" AND there is a guide item of
1776 type="cover" pointing to it AND there is a logical cover specified in a
1777 <meta name="cover"> tag, THEN, the HTML cover is discarded. -->
1778 <xsl:element name="head" namespace="{$ncx.namespace}">
1779 <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]">
1780 <xsl:element name="meta" namespace="{$ncx.namespace}">
1781 <xsl:attribute name="name">cover</xsl:attribute>
1782 <xsl:attribute name="content">
1783 <xsl:value-of select="$epub.cover.filename.id"/>
1787 <xsl:element name="meta" namespace="{$ncx.namespace}">
1788 <xsl:attribute name="name">dtb:uid</xsl:attribute>
1789 <xsl:attribute name="content"><xsl:call-template name="package-identifier"/></xsl:attribute>
1794 <xsl:when test="$rootid != ''">
1795 <xsl:variable name="title">
1796 <xsl:if test="$epub.autolabel != 0">
1797 <xsl:variable name="label.markup">
1798 <xsl:apply-templates select="key('id',$rootid)" mode="label.markup" />
1800 <xsl:if test="normalize-space($label.markup)">
1801 <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
1804 <xsl:apply-templates select="key('id',$rootid)" mode="title.markup" />
1806 <xsl:variable name="href">
1807 <xsl:call-template name="href.target.with.base.dir">
1808 <xsl:with-param name="object" select="key('id',$rootid)" />
1809 </xsl:call-template>
1811 <xsl:element name="docTitle" namespace="{$ncx.namespace}">
1812 <xsl:element name="text" namespace="{$ncx.namespace}"><xsl:value-of select="normalize-space($title)" /> </xsl:element>
1814 <xsl:element name="navMap" namespace="{$ncx.namespace}">
1815 <xsl:apply-templates select="key('id',$rootid)/*" mode="ncx" />
1819 <xsl:variable name="title">
1820 <xsl:if test="$epub.autolabel != 0">
1821 <xsl:variable name="label.markup">
1822 <xsl:apply-templates select="/*" mode="label.markup" />
1824 <xsl:if test="normalize-space($label.markup)">
1825 <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
1828 <xsl:apply-templates select="/*" mode="title.markup" />
1830 <xsl:variable name="href">
1831 <xsl:call-template name="href.target.with.base.dir">
1832 <xsl:with-param name="object" select="/" />
1833 </xsl:call-template>
1835 <xsl:element name="docTitle" namespace="{$ncx.namespace}">
1836 <xsl:element name="text" namespace="{$ncx.namespace}">
1837 <xsl:value-of select="normalize-space($title)" />
1840 <xsl:element name="navMap" namespace="{$ncx.namespace}">
1842 <xsl:when test="$root.is.a.chunk != '0'">
1843 <xsl:apply-templates select="/*" mode="ncx" />
1844 <xsl:apply-templates select="/*/*" mode="ncx" />
1847 <xsl:apply-templates select="/*/*" mode="ncx" />
1856 </xsl:call-template>
1859 <xsl:template match="book|
1881 <xsl:variable name="depth" select="count(ancestor::*)"/>
1882 <xsl:variable name="title">
1883 <xsl:if test="$epub.autolabel != 0">
1884 <xsl:variable name="label.markup">
1885 <xsl:apply-templates select="." mode="label.markup" />
1887 <xsl:if test="normalize-space($label.markup)">
1889 select="concat($label.markup,$autotoc.label.separator)" />
1892 <xsl:apply-templates select="." mode="title.markup" />
1895 <xsl:variable name="href">
1896 <xsl:call-template name="href.target.with.base.dir">
1897 <xsl:with-param name="context" select="/" />
1898 <!-- Generate links relative to the location of root file/toc.xml file -->
1899 </xsl:call-template>
1902 <xsl:variable name="id">
1903 <xsl:value-of select="generate-id(.)"/>
1905 <xsl:variable name="order">
1906 <xsl:value-of select="$depth +
1907 count(preceding::part|
1908 preceding::reference|
1909 preceding::book[parent::set]|
1912 preceding::bibliography|
1913 preceding::appendix|
1916 preceding::glossary|
1917 preceding::section[not(parent::partintro)]|
1918 preceding::sect1[not(parent::partintro)]|
1919 preceding::sect2[not(ancestor::partintro)]|
1920 preceding::sect3[not(ancestor::partintro)]|
1921 preceding::sect4[not(ancestor::partintro)]|
1922 preceding::sect5[not(ancestor::partintro)]|
1923 preceding::refentry|
1924 preceding::colophon|
1925 preceding::bibliodiv[title]|
1926 preceding::index)"/>
1929 <xsl:element name="navPoint" namespace="{$ncx.namespace}">
1930 <xsl:attribute name="id">
1931 <xsl:value-of select="$id"/>
1934 <xsl:attribute name="playOrder">
1936 <xsl:when test="/*[self::set]">
1937 <xsl:value-of select="$order"/>
1939 <xsl:when test="$root.is.a.chunk != '0'">
1940 <xsl:value-of select="$order + 1"/>
1943 <xsl:value-of select="$order - 0"/>
1947 <xsl:element name="navLabel" namespace="{$ncx.namespace}">
1948 <xsl:element name="text" namespace="{$ncx.namespace}"><xsl:value-of select="normalize-space($title)"/> </xsl:element>
1950 <xsl:element name="content" namespace="{$ncx.namespace}">
1951 <xsl:attribute name="src">
1952 <xsl:value-of select="$href"/>
1955 <xsl:if test="$depth != 0">
1956 <!-- Don't recurse on root element, but treat it as a single point so
1957 the progress bar shows all top level children -->
1958 <xsl:apply-templates select="book[parent::set]|part|reference|preface|chapter|bibliography|appendix|article|topic|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv[title]|setindex|index" mode="ncx"/>
1964 <xsl:template match="text()" mode="ncx" />
1966 <xsl:template name="package.spine">
1968 <xsl:variable name="toc.params">
1969 <xsl:call-template name="find.path.params">
1970 <xsl:with-param name="node" select="."/>
1971 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
1972 </xsl:call-template>
1975 <xsl:element namespace="http://www.idpf.org/2007/opf" name="spine">
1976 <xsl:if test="$epub.include.ncx != 0">
1977 <xsl:attribute name="toc">
1978 <xsl:value-of select="$epub.ncx.manifest.id"/>
1982 <xsl:call-template name="spine.cover"/>
1985 <xsl:if test="contains($toc.params, 'toc')">
1986 <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
1987 <xsl:attribute name="idref"> <xsl:value-of select="$epub.html.toc.id"/> </xsl:attribute>
1988 <xsl:attribute name="linear">yes</xsl:attribute>
1992 <!-- TODO: be nice to have a idref="titlepage" here -->
1994 <xsl:when test="$root.is.a.chunk != '0'">
1995 <xsl:apply-templates select="/*" mode="package.spine"/>
1998 <xsl:apply-templates select="/*/*" mode="package.spine"/>
2005 <xsl:template name="spine.cover">
2006 <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
2007 <xsl:variable name="cover.image"
2008 select="$info//mediaobject[@role='cover' or ancestor::cover]"/>
2010 <xsl:if test="$cover.image">
2011 <!-- generate the spine reference to that cover html file -->
2012 <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
2013 <xsl:attribute name="idref">
2014 <xsl:value-of select="$epub.cover.filename.id"/>
2016 <xsl:attribute name="linear">
2018 <xsl:when test="$epub.cover.linear">
2019 <xsl:text>yes</xsl:text>
2021 <xsl:otherwise>no</xsl:otherwise>
2028 <xsl:template match="*" mode="package.spine">
2029 <xsl:variable name="is.chunk">
2030 <xsl:call-template name="chunk">
2031 <xsl:with-param name="node" select="."/>
2032 </xsl:call-template>
2035 <xsl:if test="$is.chunk != 0">
2036 <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
2037 <xsl:attribute name="idref">
2038 <xsl:value-of select="concat($epub.package.id.prefix, generate-id(.))"/>
2041 <xsl:apply-templates select="*|.//refentry" mode="package.spine"/>
2045 <xsl:template match="*" mode="container">
2046 <xsl:call-template name="container"/>
2049 <xsl:template name="container">
2050 <!-- The path in rootfile does not include all of base.dir, only the last part -->
2051 <xsl:variable name="full-path-dir">
2052 <xsl:call-template name="filename-basename">
2053 <xsl:with-param name="filename" select="$chunk.base.dir"/>
2054 </xsl:call-template>
2056 <xsl:call-template name="write.chunk">
2057 <xsl:with-param name="filename">
2058 <xsl:value-of select="$epub.container.pathname" />
2060 <xsl:with-param name="method" select="'xml'" />
2061 <xsl:with-param name="encoding" select="'utf-8'" />
2062 <xsl:with-param name="indent" select="'no'" />
2063 <xsl:with-param name="quiet" select="$chunk.quietly" />
2064 <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
2065 <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
2067 <xsl:with-param name="content">
2068 <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="container">
2069 <xsl:attribute name="version">1.0</xsl:attribute>
2070 <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="rootfiles">
2071 <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="rootfile">
2072 <xsl:attribute name="full-path">
2074 select="concat($full-path-dir, $epub.package.filename)"/>
2076 <xsl:attribute name="media-type">
2077 <xsl:text>application/oebps-package+xml</xsl:text>
2083 </xsl:call-template>
2086 <xsl:template name="mimetype">
2087 <xsl:call-template name="write.text.chunk">
2088 <xsl:with-param name="filename" select="$epub.mimetype.pathname"/>
2089 <xsl:with-param name="content" select="$epub.mimetype.value"/>
2090 </xsl:call-template>
2093 <xsl:template match="mediaobject[@role='cover' or ancestor::cover]">
2094 <xsl:call-template name="write.chunk">
2095 <xsl:with-param name="filename">
2096 <xsl:value-of select="$epub.cover.pathname" />
2098 <xsl:with-param name="method" select="'xml'" />
2099 <xsl:with-param name="encoding" select="'utf-8'" />
2100 <xsl:with-param name="indent" select="'no'" />
2101 <xsl:with-param name="quiet" select="$chunk.quietly" />
2102 <xsl:with-param name="content">
2103 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="html">
2104 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="head">
2105 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="title">Cover</xsl:element>
2106 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="style">
2107 <xsl:attribute name="type">text/css</xsl:attribute>
2108 <!-- Help the cover image scale nicely in the CSS then apply a max-width to look better in Adobe Digital Editions -->
2109 <xsl:text> img { max-width: 100%; }</xsl:text>
2112 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="body">
2113 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="div">
2114 <xsl:attribute name="id">
2115 <xsl:value-of select="$epub.cover.image.id"/>
2118 <xsl:when test="imageobject[@role='front-large']">
2119 <xsl:apply-templates select="imageobject[@role='front-large']"/>
2122 <xsl:apply-templates select="imageobject[1]"/>
2126 <!-- If this is defined as an explicit cover page, then process
2127 any remaining text -->
2128 <xsl:if test="ancestor::cover">
2129 <xsl:apply-templates select="ancestor::cover/para"/>
2134 </xsl:call-template>
2137 <!-- EPUB3: use <nav> and <ol> in TOC lists -->
2138 <xsl:template name="make.toc">
2139 <xsl:param name="toc-context" select="."/>
2140 <xsl:param name="toc.title.p" select="true()"/>
2141 <xsl:param name="nodes" select="/NOT-AN-ELEMENT"/>
2143 <xsl:variable name="nodes.plus" select="$nodes | qandaset"/>
2145 <xsl:variable name="toc.title">
2146 <xsl:if test="$toc.title.p">
2148 <xsl:when test="$make.clean.html != 0">
2149 <div class="toc-title">
2150 <xsl:call-template name="gentext">
2151 <xsl:with-param name="key">TableofContents</xsl:with-param>
2152 </xsl:call-template>
2158 <xsl:call-template name="gentext">
2159 <xsl:with-param name="key">TableofContents</xsl:with-param>
2160 </xsl:call-template>
2169 <xsl:when test="$manual.toc != ''">
2170 <xsl:variable name="id">
2171 <xsl:call-template name="object.id"/>
2173 <xsl:variable name="toc" select="document($manual.toc, .)"/>
2174 <xsl:variable name="tocentry" select="$toc//tocentry[@linkend=$id]"/>
2175 <xsl:if test="$tocentry and $tocentry/*">
2177 <xsl:copy-of select="$toc.title"/>
2178 <nav epub:type="toc">
2179 <xsl:element name="{$toc.list.type}">
2180 <xsl:call-template name="manual-toc">
2181 <xsl:with-param name="tocentry" select="$tocentry/*[1]"/>
2182 </xsl:call-template>
2190 <xsl:when test="$qanda.in.toc != 0">
2192 <xsl:copy-of select="$toc.title"/>
2193 <nav epub:type="toc">
2194 <xsl:element name="{$toc.list.type}">
2195 <xsl:if test="$nodes.plus">
2196 <xsl:apply-templates select="$nodes.plus" mode="toc">
2197 <xsl:with-param name="toc-context" select="$toc-context"/>
2198 </xsl:apply-templates>
2206 <xsl:copy-of select="$toc.title"/>
2207 <nav epub:type="toc">
2208 <xsl:element name="{$toc.list.type}">
2209 <xsl:if test="$nodes">
2210 <xsl:apply-templates select="$nodes" mode="toc">
2211 <xsl:with-param name="toc-context" select="$toc-context"/>
2212 </xsl:apply-templates>
2224 <xsl:template name="list.of.titles">
2225 <xsl:param name="toc-context" select="."/>
2226 <xsl:param name="titles" select="'table'"/>
2227 <xsl:param name="nodes" select=".//table"/>
2229 <xsl:variable name="epub.type">
2231 <xsl:when test="$titles='table'">lot</xsl:when>
2232 <xsl:when test="$titles='figure'">loi</xsl:when>
2233 <xsl:when test="$titles='equation'">loi</xsl:when>
2234 <xsl:when test="$titles='example'">loi</xsl:when>
2235 <xsl:when test="$titles='procedure'">loi</xsl:when>
2236 <xsl:otherwise>loi</xsl:otherwise>
2240 <xsl:if test="$nodes">
2241 <div class="list-of-{$titles}s">
2242 <nav epub:type="{$epub.type}">
2243 <h4 class="toc-title">
2244 <xsl:call-template name="gentext">
2245 <xsl:with-param name="key">
2247 <xsl:when test="$titles='table'">ListofTables</xsl:when>
2248 <xsl:when test="$titles='figure'">ListofFigures</xsl:when>
2249 <xsl:when test="$titles='equation'">ListofEquations</xsl:when>
2250 <xsl:when test="$titles='example'">ListofExamples</xsl:when>
2251 <xsl:when test="$titles='procedure'">ListofProcedures</xsl:when>
2252 <xsl:otherwise>ListofUnknown</xsl:otherwise>
2255 </xsl:call-template>
2258 <xsl:element name="{$toc.list.type}">
2259 <xsl:apply-templates select="$nodes" mode="toc">
2260 <xsl:with-param name="toc-context" select="$toc-context"/>
2261 </xsl:apply-templates>
2268 <!-- EPUB3: add hidden="" for sections below toc.section.depth -->
2269 <xsl:template name="subtoc">
2270 <xsl:param name="toc-context" select="."/>
2271 <xsl:param name="nodes" select="NOT-AN-ELEMENT"/>
2273 <xsl:variable name="nodes.plus" select="$nodes | qandaset"/>
2275 <xsl:variable name="depth">
2277 <xsl:when test="local-name(.) = 'section'">
2278 <xsl:value-of select="count(ancestor::section) + 1"/>
2280 <xsl:when test="local-name(.) = 'sect1'">1</xsl:when>
2281 <xsl:when test="local-name(.) = 'sect2'">2</xsl:when>
2282 <xsl:when test="local-name(.) = 'sect3'">3</xsl:when>
2283 <xsl:when test="local-name(.) = 'sect4'">4</xsl:when>
2284 <xsl:when test="local-name(.) = 'sect5'">5</xsl:when>
2285 <xsl:when test="local-name(.) = 'refsect1'">1</xsl:when>
2286 <xsl:when test="local-name(.) = 'refsect2'">2</xsl:when>
2287 <xsl:when test="local-name(.) = 'refsect3'">3</xsl:when>
2288 <xsl:when test="local-name(.) = 'simplesect'">
2291 <xsl:when test="local-name(..) = 'section'">
2292 <xsl:value-of select="count(ancestor::section)"/>
2294 <xsl:when test="local-name(..) = 'sect1'">2</xsl:when>
2295 <xsl:when test="local-name(..) = 'sect2'">3</xsl:when>
2296 <xsl:when test="local-name(..) = 'sect3'">4</xsl:when>
2297 <xsl:when test="local-name(..) = 'sect4'">5</xsl:when>
2298 <xsl:when test="local-name(..) = 'sect5'">6</xsl:when>
2299 <xsl:when test="local-name(..) = 'refsect1'">2</xsl:when>
2300 <xsl:when test="local-name(..) = 'refsect2'">3</xsl:when>
2301 <xsl:when test="local-name(..) = 'refsect3'">4</xsl:when>
2302 <xsl:otherwise>1</xsl:otherwise>
2305 <xsl:otherwise>0</xsl:otherwise>
2309 <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
2311 <xsl:variable name="subtoc">
2312 <xsl:element name="{$toc.list.type}">
2314 <xsl:when test="$toc.listitem.type = 'li'
2315 and $toc.section.depth > $depth and
2316 ( ($qanda.in.toc = 0 and count($nodes)>0) or
2317 ($qanda.in.toc != 0 and count($nodes.plus)>0) )
2318 and $toc.max.depth > $depth.from.context">
2319 <!-- No @hidden attribute -->
2322 <!-- Add empty @hidden attribute if too deep -->
2323 <xsl:attribute name="hidden"></xsl:attribute>
2328 <xsl:when test="$qanda.in.toc != 0">
2329 <xsl:apply-templates mode="toc" select="$nodes.plus">
2330 <xsl:with-param name="toc-context" select="$toc-context"/>
2331 </xsl:apply-templates>
2334 <xsl:apply-templates mode="toc" select="$nodes">
2335 <xsl:with-param name="toc-context" select="$toc-context"/>
2336 </xsl:apply-templates>
2342 <xsl:variable name="subtoc.list">
2344 <xsl:when test="$toc.dd.type = ''">
2345 <xsl:copy-of select="$subtoc"/>
2348 <xsl:element name="{$toc.dd.type}">
2349 <xsl:copy-of select="$subtoc"/>
2355 <xsl:element name="{$toc.listitem.type}">
2356 <xsl:call-template name="toc.line">
2357 <xsl:with-param name="toc-context" select="$toc-context"/>
2358 </xsl:call-template>
2359 <xsl:if test="$toc.listitem.type = 'li'
2361 ( ($qanda.in.toc = 0 and count($nodes)>0) or
2362 ($qanda.in.toc != 0 and count($nodes.plus)>0) ) ">
2363 <xsl:copy-of select="$subtoc.list"/>
2368 <!-- Inserted when a title is blank to avoid epubcheck error -->
2369 <xsl:param name="toc.entry.default.text"> </xsl:param>
2371 <!-- EPUB3: either <a> or <span>, but not both -->
2372 <xsl:template name="toc.line">
2373 <xsl:param name="toc-context" select="."/>
2374 <xsl:param name="depth" select="1"/>
2375 <xsl:param name="depth.from.context" select="8"/>
2377 <xsl:variable name="title">
2378 <xsl:apply-templates select="." mode="title.markup"/>
2382 <xsl:attribute name="href">
2383 <xsl:call-template name="href.target">
2384 <xsl:with-param name="context" select="$toc-context"/>
2385 <xsl:with-param name="toc-context" select="$toc-context"/>
2386 </xsl:call-template>
2389 <!-- * if $autotoc.label.in.hyperlink is non-zero, then output the label -->
2390 <!-- * as part of the hyperlinked title -->
2391 <xsl:if test="not($autotoc.label.in.hyperlink = 0)">
2392 <xsl:variable name="label">
2393 <xsl:apply-templates select="." mode="label.markup"/>
2395 <xsl:copy-of select="$label"/>
2396 <xsl:if test="$label != ''">
2397 <xsl:value-of select="$autotoc.label.separator"/>
2402 <xsl:when test="string-length(normalize-space($title)) != 0">
2403 <xsl:copy-of select="$title"/>
2406 <xsl:value-of select="$toc.entry.default.text"/>
2412 <!-- Make sure all text is inside the <a> element for epub3 -->
2413 <xsl:template match="figure|table|example|equation|procedure" mode="toc">
2414 <xsl:param name="toc-context" select="."/>
2416 <xsl:element name="{$toc.listitem.type}">
2418 <xsl:attribute name="href">
2419 <xsl:call-template name="href.target">
2420 <xsl:with-param name="toc-context" select="$toc-context"/>
2421 </xsl:call-template>
2423 <xsl:variable name="label">
2424 <xsl:apply-templates select="." mode="label.markup"/>
2426 <xsl:copy-of select="$label"/>
2427 <xsl:if test="$label != ''">
2428 <xsl:value-of select="$autotoc.label.separator"/>
2430 <xsl:apply-templates select="." mode="titleabbrev.markup"/>
2435 <!-- Remove spans from refentry TOC lines for epub3check -->
2436 <xsl:template match="refentry" mode="toc">
2437 <xsl:param name="toc-context" select="."/>
2439 <xsl:variable name="refmeta" select=".//refmeta"/>
2440 <xsl:variable name="refentrytitle" select="$refmeta//refentrytitle"/>
2441 <xsl:variable name="refnamediv" select=".//refnamediv"/>
2442 <xsl:variable name="refname" select="$refnamediv//refname"/>
2443 <xsl:variable name="refdesc" select="$refnamediv//refdescriptor"/>
2444 <xsl:variable name="title">
2446 <xsl:when test="$refentrytitle">
2447 <xsl:apply-templates select="$refentrytitle[1]" mode="titleabbrev.markup"/>
2449 <xsl:when test="$refdesc">
2450 <xsl:apply-templates select="$refdesc" mode="titleabbrev.markup"/>
2452 <xsl:when test="$refname">
2453 <xsl:apply-templates select="$refname[1]" mode="titleabbrev.markup"/>
2458 <xsl:element name="{$toc.listitem.type}" namespace="http://www.w3.org/1999/xhtml">
2460 <xsl:attribute name="href">
2461 <xsl:call-template name="href.target">
2462 <xsl:with-param name="toc-context" select="$toc-context"/>
2463 </xsl:call-template>
2465 <xsl:copy-of select="$title"/>
2466 <xsl:if test="$annotate.toc != 0">
2467 <!-- * DocBook 5 says inlinemediaobject (among other things) -->
2468 <!-- * is allowed in refpurpose; so we need to run -->
2469 <!-- * apply-templates on refpurpose here, instead of value-of -->
2470 <!-- Set allow-anchors=0 to avoid indexterms and other links -->
2471 <xsl:text> - </xsl:text>
2472 <xsl:apply-templates select="refnamediv/refpurpose" mode="no.anchor.mode"/>
2478 <!-- Copy these here so relative document() open gets the correct css source -->
2479 <xsl:template name="generate.default.css.file">
2480 <xsl:if test="$make.clean.html != 0 and
2481 $generate.css.header = 0 and
2482 $docbook.css.source != ''">
2483 <!-- Select default file relative to stylesheet -->
2484 <xsl:variable name="css.node" select="document($docbook.css.source)/*[1]"/>
2486 <xsl:call-template name="generate.css.file">
2487 <xsl:with-param name="src" select="$docbook.css.source"/>
2488 <xsl:with-param name="css.node" select="$css.node"/>
2489 </xsl:call-template>
2493 <xsl:template name="generate.custom.css.file">
2494 <xsl:if test="$custom.css.source != '' and
2495 $generate.css.header = 0">
2496 <!-- Select custom file relative to document -->
2497 <xsl:variable name="css.node" select="document($custom.css.source,.)/*[1]"/>
2499 <xsl:call-template name="generate.css.file">
2500 <xsl:with-param name="src" select="$custom.css.source"/>
2501 <xsl:with-param name="css.node" select="$css.node"/>
2502 </xsl:call-template>