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:d="http://docbook.org/ns/docbook"
10 xmlns:exsl="http://exslt.org/common"
11 xmlns:set="http://exslt.org/sets"
12 xmlns="http://www.w3.org/1999/xhtml"
13 xmlns:epub="http://www.idpf.org/2007/ops"
14 xmlns:m="http://www.w3.org/1998/Math/MathML"
15 xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon"
16 xmlns:ssml="http://www.w3.org/2001/10/synthesis"
17 xmlns:svg="http://www.w3.org/2000/svg"
18 xmlns:opf="http://www.idpf.org/2007/opf"
19 xmlns:dc="http://purl.org/dc/elements/1.1/"
20 xmlns:cf="http://docbook.sourceforge.net/xmlns/chunkfast/1.0"
21 xmlns:date="http://exslt.org/dates-and-times"
22 xmlns:dcterms="http://purl.org/dc/terms/"
23 xmlns:ncx="http://www.daisy.org/z3986/2005/ncx/"
24 xmlns:db="http://docbook.org/ns/docbook"
25 xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
26 xmlns:str="http://exslt.org/strings"
27 xmlns:xtext="xalan://com.nwalsh.xalan.Text"
29 extension-element-prefixes="stext xtext"
30 exclude-result-prefixes="#default cf date db dc dcterms epub exsl m ncx opf pls set ssml stext str svg xtext d"
33 <xsl:import href="titlepage.templates.xsl"/>
35 <!--==============================================================-->
36 <!-- DocBook XSL Parameter settings -->
37 <!--==============================================================-->
38 <!-- separate file for toc -->
39 <xsl:param name="chunk.tocs.and.lots" select="1"/>
40 <xsl:param name="toc.section.depth" select="2"/>
41 <xsl:param name="generate.toc">
42 book toc,title,figure,table,example,equation
43 article toc,title,figure,table,example,equation
45 <xsl:param name="generate.manifest" select="0"/>
46 <xsl:param name="manifest.in.base.dir" select="1"/>
48 <!-- HTML chunk output goes to $base.dir/OEPBS -->
49 <xsl:variable name="chunk.base.dir">
51 <xsl:when test="$base.dir != '' and contains($base.dir, $epub.oebps.dir)">
52 <xsl:value-of select="substring-before($base.dir, $epub.oebps.dir)"/>
54 <!-- If epub.oebps.dir reset but base.dir still has OEBPS: -->
55 <xsl:when test="$base.dir != '' and contains($base.dir, 'OEBPS')">
56 <xsl:value-of select="substring-before($base.dir, 'OEBPS')"/>
58 <xsl:when test="string-length($base.dir) = 0"></xsl:when>
59 <!-- make sure to add trailing slash if omitted by user -->
60 <xsl:when test="substring($base.dir, string-length($base.dir), 1) = '/'">
61 <xsl:value-of select="$base.dir"/>
64 <xsl:value-of select="concat($base.dir, '/')"/>
67 <xsl:value-of select="$epub.oebps.dir"/>
68 <xsl:if test="substring($epub.oebps.dir, string-length($epub.oebps.dir), 1) != '/'">
69 <xsl:text>/</xsl:text>
74 <xsl:param name="index.links.to.section" select="0"/>
76 <!-- Epub does not yet support external links -->
77 <xsl:param name="activate.external.olinks" select="0"/>
79 <!-- Turning this on crashes ADE, which is unbelievably awesome -->
80 <xsl:param name="formal.object.break.after">0</xsl:param>
82 <xsl:param name="callout.graphics" select="1"/>
83 <xsl:param name="callout.graphics.extension">.png</xsl:param>
84 <xsl:param name="callout.graphics.number.limit" select="15"/>
85 <xsl:param name="callout.graphics.path" select="'images/callouts/'"/>
86 <xsl:param name="show.comments" select="0"/>
88 <!-- no navigation in .epub -->
89 <xsl:param name="suppress.navigation" select="'1'"/>
91 <!-- EPUB3: use ol lists in table of contents -->
92 <xsl:param name="toc.list.type">ol</xsl:param>
93 <xsl:param name="autotoc.label.in.hyperlink" select="1"/>
95 <xsl:param name="css.decoration" select="1"/>
96 <!-- generate the css file from a source file -->
97 <xsl:param name="make.clean.html" select="1"/>
98 <!-- specify the default epub3 stylesheet -->
99 <xsl:param name="docbook.css.source">docbook-epub.css.xml</xsl:param>
100 <!-- for custom CSS, use the custom.css.source param -->
101 <xsl:param name="custom.css.source"></xsl:param>
103 <!--==============================================================-->
104 <!-- New EPUB3 Parameters -->
105 <!--==============================================================-->
106 <xsl:param name="epub.version">3.0</xsl:param>
107 <!-- optional ncx for backwards compatibility -->
108 <xsl:param name="epub.include.ncx" select="1"/>
109 <xsl:param name="epub.ncx.depth">4</xsl:param> <!-- Not functional until http://code.google.com/p/epubcheck/issues/detail?id=70 is resolved -->
110 <!-- currently optional duplicate dcterms properties, may be required in future -->
111 <xsl:param name="epub.include.metadata.dcterms" select="1"/>
112 <!-- optional guide element for backwards compatibility -->
113 <xsl:param name="epub.include.guide" select="1"/>
114 <!-- some dc: currently required, to be replaced in future version -->
115 <xsl:param name="epub.include.metadata.dc.elements" select="1"/>
116 <!-- Some dc: elements will remain optional according to the spec -->
117 <xsl:param name="epub.include.optional.metadata.dc.elements" select="1"/>
118 <xsl:param name="epub.autolabel" select="0"/>
120 name="epub.vocabulary.profile.content">http://www.idpf.org/epub/30/profile/content/</xsl:param>
122 name="epub.vocabulary.profile.package">http://www.idpf.org/epub/30/profile/package/</xsl:param>
123 <xsl:param name="epub.output.epub.types" select="1"/>
124 <xsl:param name="epub.oebps.dir" select="'OEBPS'"/>
125 <xsl:variable name="epub.metainf.dir" select="'META-INF/'"/>
126 <xsl:param name="epub.ncx.filename" select="'toc.ncx'"/>
127 <xsl:variable name="epub.mimetype.filename" select="'mimetype'"/>
128 <xsl:variable name="epub.mimetype.value" select="'application/epub+zip'"/>
129 <xsl:param name="epub.container.filename" select="'container.xml'"/>
130 <xsl:param name="epub.package.filename" select="'package.opf'"/>
131 <xsl:param name="epub.cover.filename" select="concat('cover', $html.ext)"/>
132 <xsl:param name="epub.cover.linear" select="0" />
134 <!-- names of id attributes used in package files -->
135 <xsl:param name="epub.meta.identifier.id">meta-identifier</xsl:param>
136 <xsl:param name="epub.dc.identifier.id">pub-identifier</xsl:param>
137 <xsl:param name="epub.meta.title.id">meta-title</xsl:param>
138 <xsl:param name="epub.dc.title.id">pub-title</xsl:param>
139 <xsl:param name="epub.meta.language.id">meta-language</xsl:param>
140 <xsl:param name="epub.dc.language.id">pub-language</xsl:param>
141 <xsl:param name="epub.meta.creator.id">meta-creator</xsl:param>
142 <xsl:param name="epub.dc.creator.id">pub-creator</xsl:param>
143 <xsl:param name="epub.ncx.toc.id">ncxtoc</xsl:param>
144 <xsl:param name="epub.ncx.manifest.id">ncx</xsl:param>
145 <xsl:param name="epub.ncx.mediatype">application/x-dtbncx+xml</xsl:param>
146 <xsl:param name="epub.xhtml.mediatype">application/xhtml+xml</xsl:param>
147 <xsl:param name="epub.html.toc.id">htmltoc</xsl:param>
148 <xsl:param name="epub.cover.filename.id" select="'cover'"/>
149 <xsl:param name="epub.cover.image.id" select="'cover-image'"/>
151 <xsl:param name="epub.embedded.fonts"></xsl:param>
152 <xsl:param name="epub.namespace">http://www.idpf.org/2007/ops</xsl:param>
153 <xsl:param name="opf.namespace">http://www.idpf.org/2007/opf</xsl:param>
154 <xsl:param name="ncx.namespace">http://www.daisy.org/z3986/2005/ncx/</xsl:param>
155 <xsl:param name="dc.namespace">http://purl.org/dc/elements/1.1/</xsl:param>
156 <!-- prefix generated ids in package elements so they differ from content ids -->
157 <xsl:param name="epub.package.id.prefix">id-</xsl:param>
158 <!-- editor is either a creator or contributor -->
159 <xsl:param name="editor.property">contributor</xsl:param>
161 <!-- Generate full output path -->
162 <xsl:param name="epub.package.dir" select="concat($chunk.base.dir, '../')"/>
164 <xsl:param name="epub.ncx.pathname"
165 select="concat($chunk.base.dir, $epub.ncx.filename)"/>
166 <xsl:param name="epub.container.pathname"
167 select="concat($epub.package.dir, $epub.metainf.dir,
168 $epub.container.filename)"/>
169 <xsl:param name="epub.package.pathname"
170 select="concat($chunk.base.dir, $epub.package.filename)"/>
171 <xsl:param name="epub.cover.pathname"
172 select="concat($chunk.base.dir, $epub.cover.filename)"/>
173 <xsl:param name="epub.mimetype.pathname"
174 select="concat($epub.package.dir, $epub.mimetype.filename)"/>
176 <xsl:param name="kindle.extensions" select="0"/>
178 <!--==============================================================-->
179 <!-- Internal variables used for computing certain metadata -->
180 <!--==============================================================-->
181 <xsl:variable name="epub3.chunk.hierarchy">
182 <xsl:apply-templates select="/*" mode="find.chunks"/>
185 <xsl:variable name="chunkset" select="exsl:node-set($epub3.chunk.hierarchy)//cf:div"/>
187 <!--==============================================================-->
188 <!-- Template customizations -->
189 <!--==============================================================-->
191 <!-- This is used only by ncx piece -->
192 <xsl:variable name="root.is.a.chunk">
194 <xsl:when test="/*[not(self::d:book)][not(d:sect1) or not(d:section)]">
195 <xsl:text>1</xsl:text>
197 <xsl:when test="/d:book[*[last()][self::d:bookinfo]]|d:book[d:bookinfo]">
198 <xsl:text>1</xsl:text>
200 <xsl:when test="/d:book[*[last()][self::d:info]]|d:book[d:info]">
201 <xsl:text>1</xsl:text>
203 <xsl:when test="/d:bibliography">
204 <xsl:text>1</xsl:text>
207 <xsl:text>0</xsl:text>
212 <!-- EPUB3: Add generation of epub publication files -->
213 <xsl:template match="*" mode="process.root">
214 <xsl:variable name="doc" select="self::*"/>
216 <xsl:call-template name="user.preroot"/>
217 <xsl:call-template name="root.messages"/>
221 <xsl:call-template name="system.head.content">
222 <xsl:with-param name="node" select="$doc"/>
224 <xsl:call-template name="head.content">
225 <xsl:with-param name="node" select="$doc"/>
227 <xsl:call-template name="user.head.content">
228 <xsl:with-param name="node" select="$doc"/>
232 <xsl:call-template name="body.attributes"/>
233 <xsl:call-template name="user.header.content">
234 <xsl:with-param name="node" select="$doc"/>
236 <xsl:apply-templates select="."/>
237 <xsl:call-template name="user.footer.content">
238 <xsl:with-param name="node" select="$doc"/>
242 <xsl:value-of select="$html.append"/>
244 <!-- Generate any css files only once, not once per chunk -->
245 <xsl:call-template name="generate.css.files"/>
247 <xsl:call-template name="generate.epub.files"/>
251 <xsl:template name="generate.epub.files">
252 <!-- Generate epub3 files -->
254 <xsl:text>Generating EPUB package files.</xsl:text>
257 <xsl:apply-templates select="." mode="opf"/>
258 <xsl:apply-templates select="." mode="container"/>
259 <xsl:call-template name="mimetype"/>
260 <xsl:if test="$epub.include.ncx != 0">
261 <xsl:call-template name="ncx"/>
265 <!-- Generate the package file -->
266 <xsl:template match="*" mode="opf">
268 <xsl:variable name="lang">
269 <xsl:call-template name="l10n.language"/>
272 <xsl:variable name="content">
273 <!-- use xsl:element so output does not have a namespace prefix -->
274 <xsl:element name="package" namespace="{$opf.namespace}">
275 <!-- Add the package namespaces at the top -->
276 <xsl:call-template name="add.package.namespaces"/>
278 <xsl:attribute name="version">
279 <xsl:value-of select="$epub.version"/>
281 <xsl:attribute name="xml:lang">
282 <xsl:value-of select="$lang"/>
284 <!-- No profile att in 2011-09-06 spec
285 <xsl:attribute name="profile">
286 <xsl:value-of select="$epub.vocabulary.profile.package"/>
289 <xsl:attribute name="unique-identifier">
290 <xsl:value-of select="$epub.dc.identifier.id"/>
294 <xsl:call-template name="package.metadata"/>
295 <xsl:call-template name="package.manifest"/>
296 <xsl:call-template name="package.spine"/>
298 <xsl:if test="$epub.include.guide != 0">
299 <xsl:call-template name="package.guide"/>
305 <xsl:call-template name="write.chunk">
306 <xsl:with-param name="filename">
307 <xsl:value-of select="$epub.package.pathname" />
309 <xsl:with-param name="content" select="$content"/>
310 <xsl:with-param name="method" select="'xml'" />
311 <xsl:with-param name="encoding" select="'utf-8'" />
312 <xsl:with-param name="indent" select="'yes'" />
313 <xsl:with-param name="quiet" select="$chunk.quietly" />
314 <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
315 <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
319 <xsl:template name="package.metadata">
321 <xsl:element name="metadata" namespace="{$opf.namespace}">
323 <xsl:call-template name="metadata.identifier"/>
324 <xsl:call-template name="metadata.title"/>
325 <xsl:call-template name="metadata.language"/>
326 <xsl:call-template name="metadata.modified"/>
327 <xsl:call-template name="metadata.cover"/>
328 <xsl:call-template name="metadata.other.info"/>
333 <xsl:template name="doc.title">
334 <xsl:apply-templates select="." mode="title.markup"/>
337 <xsl:template name="metadata.identifier">
338 <xsl:variable name="package.id.value">
339 <xsl:call-template name="package-identifier"/>
342 <xsl:if test="$epub.include.metadata.dc.elements != 0">
343 <!-- dc:identifier element -->
345 <xsl:attribute name="id">
346 <xsl:value-of select="$epub.dc.identifier.id"/>
349 <xsl:attribute name="prefer">
350 <xsl:value-of select="$epub.meta.identifier.id"/>
353 <xsl:copy-of select="$package.id.value"/>
357 <xsl:if test="$epub.include.metadata.dcterms != 0">
358 <!-- equivalent meta identifier element -->
359 <xsl:element name="meta" namespace="{$opf.namespace}">
360 <xsl:attribute name="id">
361 <xsl:value-of select="$epub.meta.identifier.id"/>
363 <xsl:attribute name="property">dcterms:identifier</xsl:attribute>
364 <xsl:copy-of select="$package.id.value"/>
369 <xsl:template name="metadata.title">
370 <xsl:variable name="doc.title">
371 <xsl:call-template name="doc.title"/>
374 <xsl:if test="$epub.include.metadata.dc.elements != 0">
376 <xsl:attribute name="id">
377 <xsl:value-of select="$epub.dc.title.id"/>
380 <xsl:attribute name="prefer">
381 <xsl:value-of select="$epub.meta.title.id"/>
384 <xsl:value-of select="normalize-space($doc.title)"/>
388 <xsl:if test="$epub.include.metadata.dcterms != 0">
389 <!-- equivalent meta title element -->
390 <xsl:element name="meta" namespace="{$opf.namespace}">
391 <xsl:attribute name="property">dcterms:title</xsl:attribute>
392 <xsl:attribute name="id">
393 <xsl:value-of select="$epub.meta.title.id"/>
395 <xsl:value-of select="normalize-space($doc.title)"/>
400 <xsl:template name="metadata.language">
401 <xsl:variable name="lang">
402 <xsl:call-template name="l10n.language"/>
405 <xsl:if test="$epub.include.metadata.dc.elements != 0">
407 <xsl:if test="$kindle.extensions = 0">
408 <xsl:attribute name="id">
409 <xsl:value-of select="$epub.dc.language.id"/>
412 <xsl:value-of select="$lang"/>
416 <xsl:if test="$epub.include.metadata.dcterms != 0">
417 <!-- equivalent meta lang element -->
418 <xsl:element name="meta" namespace="{$opf.namespace}">
419 <xsl:attribute name="property">dcterms:language</xsl:attribute>
420 <xsl:attribute name="id">
421 <xsl:value-of select="$epub.meta.language.id"/>
423 <xsl:value-of select="$lang"/>
428 <xsl:template name="metadata.modified">
429 <xsl:variable name="local.datetime" select="date:date-time()"/>
430 <xsl:variable name="utc.datetime">
431 <xsl:call-template name="convert.date.to.utc">
432 <xsl:with-param name="date" select="$local.datetime"/>
436 <xsl:when test="string-length($utc.datetime) != 0">
437 <xsl:element name="meta" namespace="{$opf.namespace}">
438 <xsl:attribute name="property">dcterms:modified</xsl:attribute>
439 <xsl:value-of select="$utc.datetime"/>
441 <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>
444 <xsl:message terminate="yes">
445 <xsl:text>ERROR: no last-modified date value could be determined, </xsl:text>
446 <xsl:text>so cannot output required meta element with </xsl:text>
447 <xsl:text>dcterms:modified attribute. Exiting.</xsl:text>
453 <xsl:template name="convert.date.to.utc">
454 <xsl:param name="date" select="''"/>
455 <!-- input format is YYYY-MM-DDTHH:MM:SS-X:00
456 where -X:00 is the offset from UTC. -->
458 <!-- output format is YYYY-MM-DDTHH:MM:SSZ with no offset -->
459 <!-- FIX ME: Not so easy without a proper UTC date function. -->
460 <!-- Currently it just converts the local time to this format, which is
461 not the correct UTC time. -->
462 <xsl:value-of select="concat(substring($date,1,19), 'Z')"/>
465 <!-- This cover meta element used by kindlegen, at least -->
466 <xsl:template name="metadata.cover">
467 <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
468 <xsl:variable name="cover.image"
469 select="$info//d:mediaobject[@role='cover' or ancestor::d:cover]"/>
471 <xsl:if test="$cover.image">
472 <xsl:element name="meta" namespace="{$opf.namespace}">
473 <xsl:attribute name="content">
474 <xsl:value-of select="$epub.cover.image.id"/>
476 <xsl:attribute name="name">cover</xsl:attribute>
481 <xsl:template name="metadata.other.info">
482 <!-- Take info relative to selected root element -->
483 <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
485 <xsl:apply-templates select="$info/*" mode="opf.metadata"/>
488 <xsl:template match="*" mode="opf.metadata">
489 <!-- default is no output -->
492 <xsl:template match="d:authorgroup" mode="opf.metadata">
493 <xsl:apply-templates select="*" mode="opf.metadata"/>
496 <xsl:template match="d:author|d:corpauthor" mode="opf.metadata">
497 <xsl:variable name="n">
499 <xsl:when test="self::d:corpauthor">
500 <xsl:apply-templates/>
502 <xsl:when test="d:org/d:orgname">
503 <xsl:apply-templates select="d:org/d:orgname"/>
505 <xsl:when test="d:orgname">
506 <xsl:apply-templates select="d:orgname"/>
509 <xsl:call-template name="person.name">
510 <xsl:with-param name="node" select="."/>
516 <xsl:if test="string-length($n) != 0">
517 <xsl:element name="meta" namespace="{$opf.namespace}">
518 <xsl:attribute name="id">
519 <xsl:value-of select="concat($epub.meta.creator.id, position())"/>
521 <xsl:attribute name="property">dcterms:creator</xsl:attribute>
522 <xsl:value-of select="normalize-space(string($n))"/>
525 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
527 <xsl:attribute name="id">
528 <xsl:value-of select="concat($epub.dc.creator.id, position())"/>
530 <xsl:value-of select="$n"/>
536 <xsl:template match="d:editor" mode="opf.metadata">
537 <xsl:variable name="n">
539 <xsl:when test="d:orgname">
540 <xsl:apply-templates select="d:orgname"/>
543 <xsl:call-template name="person.name">
544 <xsl:with-param name="node" select="."/>
550 <xsl:variable name="name">
552 <xsl:when test="string-length($editor.property) != 0">
553 <xsl:value-of select="$editor.property"/>
556 <xsl:text>contributor</xsl:text>
561 <xsl:element name="meta" namespace="{$opf.namespace}">
562 <xsl:attribute name="property">
563 <xsl:text>dcterms:</xsl:text>
564 <xsl:value-of select="$name"/>
566 <xsl:value-of select="normalize-space($n)"/>
569 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
571 <xsl:when test="$name = 'creator'">
573 <xsl:value-of select="normalize-space($n)"/>
576 <xsl:when test="$name = 'contributor'">
578 <xsl:value-of select="normalize-space($n)"/>
582 <xsl:element namespace="{$dc.namespace}" name="{$name}">
583 <xsl:value-of select="normalize-space($n)"/>
591 <xsl:template match="d:corpcredit" mode="opf.metadata">
592 <xsl:element name="meta" namespace="{$opf.namespace}">
593 <xsl:attribute name="property">dcterms:contributor</xsl:attribute>
594 <xsl:value-of select="normalize-space(.)"/>
597 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
599 <xsl:value-of select="normalize-space(.)"/>
604 <xsl:template match="d:collab|d:othercredit" mode="opf.metadata">
605 <xsl:variable name="content">
607 <xsl:when test="d:collabname">
608 <xsl:apply-templates select="d:collabname"/>
610 <xsl:when test="d:org/d:orgname">
611 <xsl:apply-templates select="d:org/d:orgname"/>
613 <xsl:when test="d:orgname">
614 <xsl:apply-templates select="d:orgname"/>
616 <xsl:when test="d:personname|d:firstname|d:surname|d:othername">
617 <xsl:call-template name="person.name"/>
620 <xsl:value-of select="."/>
625 <xsl:element name="meta" namespace="{$opf.namespace}">
626 <xsl:attribute name="property">dcterms:contributor</xsl:attribute>
627 <xsl:value-of select="normalize-space($content)"/>
630 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
632 <xsl:value-of select="normalize-space($content)"/>
638 <xsl:template match="d:date|d:pubdate" mode="opf.metadata">
639 <xsl:variable name="date">
640 <xsl:call-template name="format.meta.date">
641 <xsl:with-param name="string" select="normalize-space(.)"/>
645 <xsl:if test="string-length($date) != 0">
646 <!-- Can only output one date for epub, pubdate has priority -->
647 <xsl:if test="self::d:pubdate or (self::d:date and not(../d:pubdate) )">
648 <xsl:element name="meta" namespace="{$opf.namespace}">
649 <xsl:attribute name="property">dcterms:date</xsl:attribute>
650 <xsl:value-of select="$date"/>
653 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
655 <xsl:value-of select="$date"/>
663 <!-- EPUB3 meta date should be of the form:
664 YYYY, YYYY-MM or YYYY-MM-DD -->
665 <xsl:template name="format.meta.date">
666 <xsl:param name="string" select="''"/>
667 <xsl:param name="node" select="."/>
669 <!-- FIXME: this needs further work, so just check the
670 string format and return the date string for now -->
671 <xsl:variable name="normalized"
672 select="translate($string, '0123456789', '##########')"/>
674 <xsl:variable name="date.ok">
676 <xsl:when test="string-length($string) = 4 and
677 $normalized = '####'">1</xsl:when>
678 <xsl:when test="string-length($string) = 7 and
679 $normalized = '####-##'">1</xsl:when>
680 <xsl:when test="string-length($string) = 10 and
681 $normalized = '####-##-##'">1</xsl:when>
682 <xsl:when test="string-length($string) = 10 and
683 $normalized = '####-##-##'">1</xsl:when>
684 <xsl:otherwise>0</xsl:otherwise>
688 <xsl:if test="$date.ok = 0">
690 <xsl:text>WARNING: wrong metadata date format: '</xsl:text>
691 <xsl:value-of select="$string"/>
692 <xsl:text>' in element </xsl:text>
693 <xsl:value-of select="local-name($node/..)"/>
694 <xsl:text>/</xsl:text>
695 <xsl:value-of select="local-name($node)"/>
696 <xsl:text>. It must be in one of these forms: </xsl:text>
697 <xsl:text>YYYY, YYYY-MM, or YYYY-MM-DD.</xsl:text>
701 <!-- return the string anyway -->
702 <xsl:value-of select="$string"/>
707 <!-- Space separate the compontents of the abstract (dropping the inline markup, sadly) -->
708 <xsl:template match="d:abstract" mode="opf.metadata">
709 <xsl:variable name="content">
710 <xsl:for-each select="d:formalpara|d:para|d:simpara|d:title">
712 <xsl:when test="self::d:formalpara">
713 <xsl:value-of select="normalize-space(string(d:title))"/>
714 <xsl:text>: </xsl:text>
715 <xsl:value-of select="normalize-space(string(d:para))"/>
718 <xsl:value-of select="normalize-space(string(.))"/>
721 <xsl:if test="self::d:title">
722 <xsl:text>:</xsl:text>
724 <xsl:if test="not(position() = last())">
725 <xsl:text> </xsl:text>
730 <xsl:element name="meta" namespace="{$opf.namespace}">
731 <xsl:attribute name="property">dcterms:description</xsl:attribute>
732 <xsl:copy-of select="$content"/>
735 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
737 <xsl:copy-of select="$content"/>
742 <xsl:template match="d:subjectset" mode="opf.metadata">
743 <xsl:apply-templates select="d:subject/d:subjectterm" mode="opf.metadata"/>
746 <xsl:template match="d:subjectterm" mode="opf.metadata">
747 <xsl:element name="meta" namespace="{$opf.namespace}">
748 <xsl:attribute name="property">dcterms:subject</xsl:attribute>
749 <xsl:value-of select="normalize-space(string(.))"/>
752 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
754 <xsl:value-of select="normalize-space(string(.))"/>
759 <xsl:template match="d:keywordset" mode="opf.metadata">
760 <xsl:apply-templates select="d:keyword" mode="opf.metadata"/>
763 <xsl:template match="d:keyword" mode="opf.metadata">
764 <xsl:element name="meta" namespace="{$opf.namespace}">
765 <xsl:attribute name="property">dcterms:subject</xsl:attribute>
766 <xsl:value-of select="normalize-space(string(.))"/>
769 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
771 <xsl:value-of select="normalize-space(string(.))"/>
776 <xsl:template match="d:publisher" mode="opf.metadata">
777 <xsl:apply-templates select="d:publishername" mode="opf.metadata"/>
780 <xsl:template match="d:publishername" mode="opf.metadata">
781 <xsl:element name="meta" namespace="{$opf.namespace}">
782 <xsl:attribute name="property">dcterms:publisher</xsl:attribute>
783 <xsl:value-of select="normalize-space(string(.))"/>
786 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
788 <xsl:value-of select="normalize-space(string(.))"/>
793 <xsl:template match="d:bibliocoverage" mode="opf.metadata">
794 <xsl:element name="meta" namespace="{$opf.namespace}">
795 <xsl:attribute name="property">dcterms:coverage</xsl:attribute>
796 <xsl:value-of select="normalize-space(string(.))"/>
799 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
801 <xsl:value-of select="normalize-space(string(.))"/>
806 <xsl:template match="d:bibliorelation" mode="opf.metadata">
807 <xsl:element name="meta" namespace="{$opf.namespace}">
808 <xsl:attribute name="property">dcterms:relation</xsl:attribute>
809 <xsl:value-of select="normalize-space(string(.))"/>
812 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
814 <xsl:value-of select="normalize-space(string(.))"/>
819 <xsl:template match="d:bibliosource" mode="opf.metadata">
820 <xsl:element name="meta" namespace="{$opf.namespace}">
821 <xsl:attribute name="property">dcterms:source</xsl:attribute>
822 <xsl:value-of select="normalize-space(string(.))"/>
825 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
827 <xsl:value-of select="normalize-space(string(.))"/>
832 <xsl:template match="d:copyright" mode="opf.metadata">
833 <xsl:variable name="copyright.date">
834 <xsl:call-template name="copyright.years">
835 <xsl:with-param name="years" select="d:year"/>
836 <xsl:with-param name="print.ranges" select="$make.year.ranges"/>
837 <xsl:with-param name="single.year.ranges" select="$make.single.year.ranges"/>
841 <!-- if no docbook date element, use copyright year for single date metadata -->
842 <xsl:if test="not(../d:date) and not(../d:pubdate)">
843 <xsl:variable name="date.content">
844 <xsl:call-template name="format.meta.date">
845 <xsl:with-param name="string">
846 <xsl:call-template name="copyright.years">
847 <xsl:with-param name="years" select="d:year[last()]"/>
848 <xsl:with-param name="print.ranges" select="0"/>
849 <xsl:with-param name="single.year.ranges" select="0"/>
854 <xsl:element name="meta" namespace="{$opf.namespace}">
855 <xsl:attribute name="property">dcterms:date</xsl:attribute>
856 <xsl:copy-of select="$date.content"/>
858 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
860 <xsl:copy-of select="$date.content"/>
865 <xsl:variable name="rights.content">
866 <xsl:call-template name="gentext">
867 <xsl:with-param name="key" select="'Copyright'"/>
869 <xsl:call-template name="gentext.space"/>
870 <xsl:text>©</xsl:text>
871 <xsl:call-template name="gentext.space"/>
872 <xsl:value-of select="$copyright.date"/>
873 <xsl:call-template name="gentext.space"/>
874 <xsl:apply-templates select="d:holder" mode="titlepage.mode"/>
877 <xsl:element name="meta" namespace="{$opf.namespace}">
878 <xsl:attribute name="property">dcterms:rights</xsl:attribute>
879 <xsl:copy-of select="$rights.content"/>
881 <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
883 <xsl:copy-of select="$rights.content"/>
887 <xsl:element name="meta" namespace="{$opf.namespace}">
888 <xsl:attribute name="property">dcterms:rightsHolder</xsl:attribute>
889 <xsl:apply-templates select="d:holder" mode="titlepage.mode"/>
893 <xsl:template name="package.guide">
895 <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
897 <xsl:variable name="toc.params">
898 <xsl:call-template name="find.path.params">
899 <xsl:with-param name="node" select="."/>
900 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
904 <xsl:if test="contains($toc.params, 'toc') or
906 $info//d:mediaobject[@role='cover' or ancestor::d:cover]">
907 <xsl:element namespace="{$opf.namespace}" name="guide">
908 <xsl:if test="$info/d:cover or
909 $info//d:mediaobject[@role='cover' or ancestor::d:cover]">
910 <xsl:element namespace="{$opf.namespace}" name="reference">
911 <xsl:attribute name="href">
912 <xsl:value-of select="$epub.cover.filename" />
914 <xsl:attribute name="type">cover</xsl:attribute>
915 <xsl:attribute name="title">Cover</xsl:attribute>
919 <xsl:if test="contains($toc.params, 'toc')">
920 <xsl:element namespace="{$opf.namespace}" name="reference">
921 <xsl:attribute name="href">
922 <xsl:call-template name="toc-href">
923 <xsl:with-param name="node" select="."/>
926 <xsl:attribute name="type">toc</xsl:attribute>
927 <xsl:attribute name="title">Table of Contents</xsl:attribute>
935 <xsl:template name="package-identifier">
937 <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
940 <xsl:when test="$info/d:biblioid">
941 <xsl:if test="$info/d:biblioid[1][@class = 'doi' or
946 <xsl:text>urn:</xsl:text>
947 <xsl:value-of select="$info/d:biblioid[1]/@class"/>
948 <xsl:text>:</xsl:text>
950 <xsl:value-of select="normalize-space($info/d:biblioid[1])"/>
952 <xsl:when test="$info/d:isbn">
953 <xsl:text>urn:isbn:</xsl:text>
954 <xsl:value-of select="$info/d:isbn[1]"/>
956 <xsl:when test="$info/d:issn">
957 <xsl:text>urn:issn:</xsl:text>
958 <xsl:value-of select="$info/d:issn[1]"/>
962 <xsl:when test="$info/d:invpartnumber">
963 <xsl:value-of select="$info/d:invpartnumber[1]"/>
965 <xsl:when test="$info/d:issuenum">
966 <xsl:value-of select="$info/d:issuenum[1]"/>
968 <xsl:when test="$info/d:productnumber">
969 <xsl:value-of select="$info/d:productnumber[1]"/>
971 <xsl:when test="$info/d:seriesvolnums">
972 <xsl:value-of select="$info/d:seriesvolnums[1]"/>
974 <xsl:when test="$info/d:volumenum">
975 <xsl:value-of select="$info/d:volumenum[1]"/>
978 <xsl:when test="$info/d:pubsnumber">
979 <xsl:value-of select="$info/d:pubsnumber[1]"/>
982 <xsl:text>_</xsl:text>
984 <xsl:when test="@id">
985 <xsl:value-of select="@id"/>
987 <xsl:when test="@xml:id">
988 <xsl:value-of select="@xml:id"/>
991 <!-- TODO: Do UUIDs here -->
992 <xsl:value-of select="generate-id(.)"/>
999 <!-- EPUB3: add epub:type attribute where appropriate -->
1000 <xsl:template match="*" mode="common.html.attributes">
1001 <xsl:param name="class" select="local-name(.)"/>
1002 <xsl:param name="inherit" select="0"/>
1003 <xsl:call-template name="generate.html.lang"/>
1004 <xsl:call-template name="dir">
1005 <xsl:with-param name="inherit" select="$inherit"/>
1006 </xsl:call-template>
1007 <xsl:apply-templates select="." mode="class.attribute">
1008 <xsl:with-param name="class" select="$class"/>
1009 </xsl:apply-templates>
1010 <xsl:call-template name="generate.html.title"/>
1011 <xsl:apply-templates select="." mode="epub.type"/>
1014 <xsl:template match="*" mode="epub.type" priority="-1"/>
1016 <xsl:template match="d:chapter
1032 |d:part" mode="epub.type">
1033 <xsl:variable name="type" select="local-name()"/>
1035 <xsl:if test="$epub.output.epub.types != 0">
1036 <xsl:attribute name="epub:type">
1037 <xsl:value-of select="$type"/>
1042 <xsl:template match="d:section[parent::d:chapter] | d:sect1" mode="epub.type">
1043 <xsl:if test="$epub.output.epub.types != 0">
1044 <xsl:attribute name="epub:type">subchapter</xsl:attribute>
1048 <xsl:template match="d:section[not(parent::d:chapter)] |
1053 d:sect6" mode="epub.type">
1054 <xsl:if test="$epub.output.epub.types != 0">
1055 <xsl:attribute name="epub:type">division</xsl:attribute>
1059 <xsl:template match="d:note|d:tip|d:caution|d:important" mode="epub.type">
1060 <xsl:if test="$epub.output.epub.types != 0">
1061 <xsl:attribute name="epub:type">notice</xsl:attribute>
1065 <xsl:template match="d:orderedlist|d:itemizedlist|d:variablelist|d:simplelist" mode="epub.type">
1066 <xsl:if test="$epub.output.epub.types != 0">
1067 <xsl:attribute name="epub:type">list</xsl:attribute>
1071 <xsl:template match="d:listitem" mode="epub.type">
1072 <xsl:if test="$epub.output.epub.types != 0">
1073 <xsl:attribute name="epub:type">list-item</xsl:attribute>
1077 <!-- EPUB3: to add attributes to root output element -->
1078 <xsl:template name="root.attributes">
1079 <!-- collect and output all namespace declarations -->
1080 <xsl:call-template name="all.namespaces"/>
1083 <xsl:template name="all.namespaces">
1084 <!-- add the epub3 namespaces to the top output element -->
1085 <xsl:variable name="temp">
1093 <xsl:variable name="nodes" select="exsl:node-set($temp)"/>
1094 <xsl:for-each select="$nodes//*/namespace::*">
1095 <xsl:copy-of select="."/>
1100 <xsl:template name="add.package.namespaces">
1101 <!-- add the epub3 package namespaces to the top output element -->
1102 <xsl:variable name="temp">
1107 <xsl:variable name="nodes" select="exsl:node-set($temp)"/>
1108 <xsl:for-each select="$nodes//*[local-name(.) ='foo']/namespace::*">
1109 <xsl:if test="contains(., 'purl.org')">
1110 <xsl:copy-of select="."/>
1117 <xsl:template name="footnotes.attributes">
1118 <xsl:if test="$epub.output.epub.types != 0">
1119 <xsl:attribute name="epub:type">footnotes</xsl:attribute>
1123 <xsl:template name="package.manifest">
1124 <xsl:element name="manifest" namespace="{$opf.namespace}">
1125 <xsl:if test="$epub.include.ncx != 0">
1126 <xsl:call-template name="manifest.ncx"/>
1128 <xsl:call-template name="manifest.fonts"/>
1129 <xsl:call-template name="manifest.toc"/>
1130 <xsl:call-template name="manifest.css"/>
1131 <xsl:call-template name="manifest.cover"/>
1132 <xsl:call-template name="manifest.other.items"/>
1133 <xsl:call-template name="manifest.content.items"/>
1134 <xsl:call-template name="user.manifest.items"/>
1138 <xsl:template name="user.manifest.items"/>
1140 <xsl:template name="manifest.css">
1141 <xsl:if test="$html.stylesheet != ''">
1142 <xsl:call-template name="css.item">
1143 <xsl:with-param name="stylesheets" select="$html.stylesheet"/>
1144 </xsl:call-template>
1146 <xsl:if test="string-length($docbook.css.source) != 0">
1147 <xsl:variable name="dfilename">
1148 <xsl:call-template name="css.output.filename">
1149 <xsl:with-param name="src" select="$docbook.css.source"/>
1150 </xsl:call-template>
1152 <xsl:element namespace="{$opf.namespace}" name="item">
1153 <xsl:attribute name="media-type">text/css</xsl:attribute>
1154 <xsl:attribute name="id">docbook-css</xsl:attribute>
1155 <xsl:attribute name="href">
1156 <xsl:value-of select="$dfilename"/>
1160 <xsl:if test="string-length($custom.css.source) != 0">
1161 <xsl:variable name="cfilename">
1162 <xsl:call-template name="css.output.filename">
1163 <xsl:with-param name="src" select="$custom.css.source"/>
1164 </xsl:call-template>
1166 <xsl:element namespace="{$opf.namespace}" name="item">
1167 <xsl:attribute name="media-type">text/css</xsl:attribute>
1168 <xsl:attribute name="id">custom-css</xsl:attribute>
1169 <xsl:attribute name="href">
1170 <xsl:value-of select="$cfilename"/>
1176 <xsl:template name="css.item">
1177 <xsl:param name="stylesheets" select="''"/>
1178 <xsl:param name="count" select="1"/>
1181 <xsl:when test="contains($stylesheets, ' ')">
1182 <xsl:variable name="css.filename" select="substring-before($stylesheets, ' ')"/>
1183 <xsl:if test="$css.filename != ''">
1184 <xsl:element namespace="{$opf.namespace}" name="item">
1185 <xsl:attribute name="media-type">text/css</xsl:attribute>
1186 <xsl:attribute name="id">
1187 <xsl:text>html-css</xsl:text>
1188 <xsl:if test="$count > 1">
1189 <xsl:value-of select="$count"/>
1192 <xsl:attribute name="href">
1193 <xsl:value-of select="$css.filename"/>
1198 <xsl:call-template name="css.item">
1199 <xsl:with-param name="stylesheets" select="substring-after($stylesheets, ' ')"/>
1200 <xsl:with-param name="count" select="$count + 1"/>
1201 </xsl:call-template>
1204 <xsl:if test="$stylesheets != ''">
1205 <xsl:element namespace="{$opf.namespace}" name="item">
1206 <xsl:attribute name="media-type">text/css</xsl:attribute>
1207 <xsl:attribute name="id">
1208 <xsl:text>html-css</xsl:text>
1209 <xsl:if test="$count > 1">
1210 <xsl:value-of select="$count"/>
1213 <xsl:attribute name="href">
1214 <xsl:value-of select="$stylesheets"/>
1222 <xsl:template name="manifest.ncx">
1223 <xsl:element name="item" namespace="{$opf.namespace}">
1224 <xsl:attribute name="id">
1225 <xsl:value-of select="$epub.ncx.manifest.id"/>
1227 <xsl:attribute name="href">
1228 <xsl:value-of select="$epub.ncx.filename"/>
1230 <xsl:attribute name="media-type">
1231 <xsl:value-of select="$epub.ncx.mediatype"/>
1236 <xsl:template name="manifest.fonts">
1237 <xsl:param name="font.list" select="$epub.embedded.fonts"/>
1238 <xsl:param name="count" select="0"/>
1241 <xsl:when test="$font.list != '' and
1242 not(contains($font.list, ','))">
1243 <xsl:call-template name="embedded-font-item">
1244 <xsl:with-param name="font.file" select="normalize-space($font.list)"/>
1245 <xsl:with-param name="font.order" select="$count + 1"/>
1246 </xsl:call-template>
1248 <xsl:when test="$font.list != '' and
1249 contains($font.list, ',')">
1250 <xsl:variable name="this.font"
1251 select="substring-before($font.list, ',')"/>
1252 <xsl:variable name="rest"
1253 select="substring-after($font.list, ',')"/>
1255 <xsl:call-template name="embedded-font-item">
1256 <xsl:with-param name="font.file" select="normalize-space($this.font)"/>
1257 <xsl:with-param name="font.order" select="$count + 1"/>
1258 </xsl:call-template>
1260 <!-- recurse to process the rest -->
1261 <xsl:call-template name="manifest.fonts">
1262 <xsl:with-param name="font.list" select="$rest"/>
1263 <xsl:with-param name="count" select="$count + 1"/>
1264 </xsl:call-template>
1271 <xsl:template name="embedded-font-item">
1272 <xsl:param name="font.file"/>
1273 <xsl:param name="font.order" select="1"/>
1275 <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
1276 <xsl:attribute name="id">
1277 <xsl:value-of select="concat('epub.embedded.font.', $font.order)"/>
1279 <xsl:attribute name="href">
1280 <xsl:value-of select="$font.file"/>
1283 <xsl:when test="contains($font.file, '.otf')">
1284 <xsl:attribute name="media-type">application/vnd.ms-opentype</xsl:attribute>
1286 <xsl:when test="contains($font.file, '.woff')">
1287 <xsl:attribute name="media-type">application/font-woff</xsl:attribute>
1291 <xsl:text>WARNING: embedded fonts should be OpenType or WOFF! (</xsl:text>
1292 <xsl:value-of select="$font.file"/>
1293 <xsl:text>)</xsl:text>
1300 <!--Misc items in the manifest based on content -->
1301 <xsl:template name="manifest.other.items">
1305 <xsl:template name="manifest.cover">
1306 <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
1307 <xsl:variable name="cover.image"
1308 select="$info//d:mediaobject[@role='cover' or ancestor::d:cover]"/>
1310 <xsl:if test="$cover.image">
1312 <!-- generate the manifest link to that page -->
1313 <xsl:variable name="olist" select="$cover.image/d:imageobject|$cover.image/d:imageobjectco
1314 |$cover.image/d:videoobject|$cover.image/d:audioobject
1315 |$cover.image/d:textobject"/>
1317 <xsl:variable name="object.index">
1318 <xsl:call-template name="select.mediaobject.index">
1319 <xsl:with-param name="olist" select="$olist"/>
1320 <xsl:with-param name="count" select="1"/>
1321 </xsl:call-template>
1324 <xsl:variable name="object" select="$olist[position() = $object.index]"/>
1326 <xsl:variable name="output_filename">
1327 <xsl:call-template name="mediaobject.filename">
1328 <xsl:with-param name="object" select="$object"/>
1329 </xsl:call-template>
1332 <xsl:variable name="image.filename">
1333 <xsl:if test="$img.src.path != '' and
1334 not(starts-with($output_filename, '/')) and
1335 not(contains($output_filename, '://'))">
1336 <xsl:value-of select="$img.src.path"/>
1338 <xsl:value-of select="$output_filename"/>
1340 <xsl:variable name="image.extension">
1341 <xsl:call-template name="filename-extension">
1342 <xsl:with-param name="filename" select="$image.filename"/>
1343 </xsl:call-template>
1346 <xsl:variable name="image.type">
1347 <xsl:call-template name="graphic.format.content-type">
1348 <xsl:with-param name="format" select="translate($image.extension,
1349 &lowercase;, &uppercase;)"/>
1350 </xsl:call-template>
1353 <!-- Reference to cover html file -->
1354 <xsl:element namespace="{$opf.namespace}" name="item">
1355 <xsl:attribute name="id">
1356 <xsl:value-of select="$epub.cover.filename.id"/>
1358 <xsl:attribute name="href">
1359 <xsl:value-of select="$epub.cover.filename"/>
1361 <xsl:attribute name="media-type">
1362 <xsl:value-of select="$epub.xhtml.mediatype"/>
1366 <!-- special item with property="cover-image" -->
1367 <xsl:element namespace="{$opf.namespace}" name="item">
1368 <xsl:attribute name="id">
1369 <xsl:value-of select="$epub.cover.image.id"/>
1371 <xsl:attribute name="properties">cover-image</xsl:attribute>
1372 <xsl:attribute name="href">
1373 <xsl:value-of select="$image.filename"/>
1375 <xsl:if test="$image.type">
1376 <xsl:attribute name="media-type">
1377 <xsl:value-of select="$image.type"/>
1382 <!-- And generate the cover html file -->
1383 <xsl:apply-templates select="$cover.image"/>
1388 <xsl:template name="manifest.toc">
1389 <xsl:variable name="toc.params">
1390 <xsl:call-template name="find.path.params">
1391 <xsl:with-param name="node" select="."/>
1392 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
1393 </xsl:call-template>
1396 <xsl:if test="contains($toc.params, 'toc')">
1397 <xsl:element namespace="{$opf.namespace}" name="item">
1398 <xsl:attribute name="id">
1399 <xsl:value-of select="$epub.html.toc.id"/>
1401 <xsl:attribute name="properties">nav</xsl:attribute>
1402 <xsl:attribute name="media-type">
1403 <xsl:value-of select="$epub.xhtml.mediatype"/>
1405 <xsl:attribute name="href">
1406 <xsl:call-template name="toc-href">
1407 <xsl:with-param name="node" select="."/>
1408 </xsl:call-template>
1414 <xsl:template name="toc-href">
1415 <xsl:param name="node" select="."/>
1417 <xsl:apply-templates select="$node" mode="recursive-chunk-filename">
1418 <xsl:with-param name="recursive" select="true()"/>
1419 </xsl:apply-templates>
1420 <xsl:text>-toc</xsl:text>
1421 <xsl:value-of select="$html.ext"/>
1424 <xsl:template match="*" mode="recursive-chunk-filename">
1425 <!-- placeholder for real template in chunking stylesheet -->
1426 <xsl:value-of select="concat(local-name(.), '-', generate-id(.))"/>
1429 <xsl:template name="manifest.content.items">
1430 <xsl:apply-templates select="." mode="package.manifest"/>
1431 <xsl:call-template name="manifest.images"/>
1434 <xsl:template match="text()" mode="package.manifest"/>
1436 <xsl:template match="d:mediaobject|d:mediaobjectco|d:inlinemediaobject" priority="1"
1437 mode="package.manifest">
1438 <!-- These are handled out of line so a unique list is created
1439 to remove duplicate references -->
1442 <xsl:template match="*" mode="package.manifest">
1444 <xsl:variable name="is.chunk">
1445 <xsl:call-template name="chunk">
1446 <xsl:with-param name="node" select="."/>
1447 </xsl:call-template>
1450 <xsl:if test="$is.chunk != 0">
1451 <xsl:variable name="href">
1452 <xsl:call-template name="href.target.with.base.dir">
1453 <xsl:with-param name="context" select="/"/>
1454 </xsl:call-template>
1457 <xsl:variable name="id" select="concat($epub.package.id.prefix, generate-id())"/>
1459 <xsl:variable name="properties.set">
1460 <xsl:call-template name="svg.property"/>
1461 <xsl:text> </xsl:text>
1462 <xsl:call-template name="mathml.property"/>
1465 <xsl:variable name="properties" select="normalize-space($properties.set)"/>
1467 <xsl:element namespace="{$opf.namespace}" name="item">
1468 <xsl:attribute name="id">
1469 <xsl:value-of select="$id"/>
1471 <xsl:attribute name="href">
1472 <xsl:value-of select="$href"/>
1474 <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
1475 <xsl:if test="string-length($properties) != 0">
1476 <xsl:attribute name="properties">
1477 <xsl:value-of select="$properties"/>
1482 <xsl:apply-templates mode="package.manifest"/>
1486 <xsl:template name="svg.property">
1487 <xsl:param name="this.chunk" select="."/>
1489 <xsl:variable name="genid" select="generate-id($this.chunk)"/>
1491 <!-- get the chunkfast div element for this chunk -->
1492 <xsl:variable name="div" select="$chunkset[@id=$genid or @xml:id=$genid]"/>
1494 <!-- get the chunkfast div element the next chunk -->
1495 <xsl:variable name="nextdiv"
1496 select="($div/following-sibling::cf:div|
1497 $div/following::cf:div|
1500 <!-- get the element corresponding to the next chunk -->
1501 <xsl:variable name="next.chunk" select="key('genid', ($nextdiv/@id|$nextdiv/@xml:id)[1])"/>
1504 <xsl:when test="$next.chunk">
1505 <xsl:variable name="this.imagedata"
1506 select="$this.chunk//d:mediaobject"/>
1507 <xsl:variable name="before.next"
1508 select="$next.chunk/preceding::d:mediaobject"/>
1510 <!-- select for an SVG imagedata in the intersection of them -->
1511 <xsl:variable name="mediaobject.set"
1512 select="$this.imagedata[count(.|$before.next) = count($before.next)]"/>
1513 <xsl:variable name="svg.imagedata">
1514 <xsl:for-each select="$mediaobject.set">
1515 <xsl:variable name="olist" select="d:imageobject[not(@role = 'poster')] |
1517 <xsl:variable name="mediaobject.index">
1518 <xsl:call-template name="select.mediaobject.index">
1519 <xsl:with-param name="olist" select="$olist"/>
1520 </xsl:call-template>
1522 <xsl:variable name="object" select="$olist[position() = $mediaobject.index]"/>
1523 <xsl:if test="$object/d:imagedata[contains(
1524 substring(@fileref, string-length(@fileref)-3,4), '.svg')]">
1525 <xsl:text>svg</xsl:text>
1530 <xsl:if test="contains($svg.imagedata, 'svg')">
1531 <xsl:text>svg</xsl:text>
1535 <xsl:variable name="mediaobject.set"
1536 select="$this.chunk//d:mediaobject"/>
1537 <xsl:variable name="svg.imagedata">
1538 <xsl:for-each select="$mediaobject.set">
1539 <xsl:variable name="olist" select="d:imageobject[not(@role = 'poster')] |
1541 <xsl:variable name="mediaobject.index">
1542 <xsl:call-template name="select.mediaobject.index">
1543 <xsl:with-param name="olist" select="$olist"/>
1544 </xsl:call-template>
1546 <xsl:variable name="object" select="$olist[position() = $mediaobject.index]"/>
1547 <xsl:if test="$object/d:imagedata[contains(
1548 substring(@fileref, string-length(@fileref)-3,4), '.svg')]">
1549 <xsl:text>svg</xsl:text>
1554 <xsl:if test="contains($svg.imagedata, 'svg')">
1555 <xsl:text>svg</xsl:text>
1562 <xsl:template name="mathml.property">
1563 <xsl:param name="this.chunk" select="."/>
1565 <xsl:variable name="genid" select="generate-id($this.chunk)"/>
1567 <!-- get the chunkfast div element for this chunk -->
1568 <xsl:variable name="div" select="$chunkset[@id=$genid or @xml:id=$genid]"/>
1570 <!-- get the chunkfast div element the next chunk -->
1571 <xsl:variable name="nextdiv"
1572 select="($div/following-sibling::cf:div|
1573 $div/following::cf:div|
1576 <!-- get the element corresponding to the next chunk -->
1577 <xsl:variable name="next.chunk" select="key('genid', ($nextdiv/@id|$nextdiv/@xml:id)[1])"/>
1579 <xsl:variable name="this.math"
1580 select="$this.chunk//m:*"/>
1581 <xsl:variable name="before.next"
1582 select="$next.chunk/preceding::m:*"/>
1584 <!-- select for an SVG imagedata in the intersection of them -->
1585 <xsl:variable name="intersection"
1586 select="$this.math[count(.|$before.next) = count($before.next)]"/>
1588 <xsl:if test="count($intersection) != 0">
1589 <xsl:text>mathml</xsl:text>
1593 <xsl:template name="manifest.image.item">
1596 <!-- Need a uniqued list of images -->
1597 <xsl:template name="manifest.images">
1598 <xsl:message>Generating image list ...</xsl:message>
1599 <xsl:variable name="imagelist">
1601 <xsl:when test="$rootid != ''">
1602 <xsl:apply-templates select="key('id', $rootid)" mode="enumerate-images"/>
1605 <xsl:apply-templates select="/" mode="enumerate-images"/>
1611 <xsl:when test="$exsl.node.set.available != 0 and
1612 function-available('set:distinct')">
1613 <xsl:for-each select="set:distinct(exsl:node-set($imagelist)/*)">
1614 <xsl:if test="string-length(tmp-href) != 0">
1615 <!-- convert the child elements to attributes -->
1616 <xsl:element name="item" namespace="{$opf.namespace}">
1617 <xsl:attribute name="id">
1618 <xsl:value-of select="generate-id()"/>
1620 <xsl:attribute name="href">
1621 <xsl:value-of select="tmp-href"/>
1623 <xsl:attribute name="media-type">
1624 <xsl:value-of select="media-type"/>
1630 <xsl:when test="$exsl.node.set.available != 0">
1631 <xsl:for-each select="exsl:node-set($imagelist)/*">
1632 <xsl:element name="item" namespace="{$opf.namespace}">
1633 <xsl:attribute name="id">
1634 <xsl:value-of select="generate-id()"/>
1636 <xsl:attribute name="href">
1637 <xsl:value-of select="tmp-href"/>
1639 <xsl:attribute name="media-type">
1640 <xsl:value-of select="media-type"/>
1646 <xsl:message terminate="yes">
1647 <xsl:text>ERROR: cannot process images list without </xsl:text>
1648 <xsl:text>exsl:node-set() function</xsl:text>
1650 <!-- cannot do this without node-set() -->
1656 <xsl:template match="*" mode="enumerate-images">
1657 <xsl:apply-templates mode="enumerate-images"/>
1660 <xsl:template match="text()" mode="enumerate-images"/>
1662 <xsl:template match="d:graphic|d:inlinegraphic[@format!='linespecific']"
1663 mode="enumerate-images">
1666 <!-- cover image handled separates to give it an extra property attribute -->
1667 <xsl:template match="d:mediaobject[@role='cover' or ancestor::d:cover]"
1668 mode="enumerate-images"/>
1670 <xsl:template match="d:mediaobject|d:inlinemediaobject" mode="enumerate-images">
1672 <xsl:variable name="olist"
1673 select="d:imageobject[not(@role = 'poster')]
1679 <xsl:variable name="object.index">
1680 <xsl:call-template name="select.mediaobject.index">
1681 <xsl:with-param name="olist" select="$olist"/>
1682 <xsl:with-param name="count" select="1"/>
1683 </xsl:call-template>
1686 <xsl:variable name="object" select="$olist[position() = $object.index]"/>
1688 <xsl:apply-templates select="$object" mode="enumerate-images"/>
1690 <!-- also include a poster image if present -->
1691 <xsl:apply-templates select="d:imageobject[@role = 'poster']" mode="enumerate-images"/>
1695 <xsl:template match="d:imageobject|d:videoobject|d:audioobject" mode="enumerate-images">
1696 <xsl:param name="object" select="."/>
1698 <xsl:if test="$object">
1699 <xsl:for-each select="$object/d:imagedata|$object/d:videodata|$object/d:audiodata">
1700 <xsl:variable name="output_filename">
1701 <xsl:call-template name="mediaobject.filename">
1702 <xsl:with-param name="object" select="."/>
1703 </xsl:call-template>
1706 <xsl:variable name="image.filename">
1707 <xsl:if test="$img.src.path != '' and
1708 not(starts-with($output_filename, '/')) and
1709 not(contains($output_filename, '://'))">
1710 <xsl:value-of select="$img.src.path"/>
1712 <xsl:value-of select="$output_filename"/>
1715 <xsl:variable name="image.extension">
1716 <xsl:call-template name="filename-extension">
1717 <xsl:with-param name="filename" select="$image.filename"/>
1718 </xsl:call-template>
1721 <xsl:variable name="image.type">
1722 <xsl:call-template name="graphic.format.content-type">
1723 <xsl:with-param name="format" select="translate($image.extension,
1724 &lowercase;, &uppercase;)"/>
1725 </xsl:call-template>
1728 <xsl:element name="tmp-filename" namespace="">
1729 <xsl:element name="tmp-href" namespace="">
1730 <xsl:value-of select="$image.filename"/>
1732 <xsl:element name="media-type" namespace="">
1733 <xsl:value-of select="$image.type"/>
1741 <!-- Add in the generated images -->
1742 <xsl:template match="d:note|d:caution|d:warning|d:important|d:tip" mode="enumerate-images">
1743 <xsl:if test="$admon.graphics != 0">
1744 <xsl:variable name="image.filename">
1745 <xsl:call-template name="admon.graphic"/>
1748 <xsl:variable name="image.type">
1749 <xsl:call-template name="graphic.format.content-type">
1750 <xsl:with-param name="format" select="translate(
1751 substring-after($admon.graphics.extension,'.'),
1752 &lowercase;, &uppercase;)"/>
1753 </xsl:call-template>
1756 <xsl:element name="tmp-filename" namespace="">
1757 <xsl:element name="tmp-href" namespace="">
1758 <xsl:value-of select="$image.filename"/>
1760 <xsl:element name="media-type" namespace="">
1761 <xsl:value-of select="$image.type"/>
1768 <xsl:template match="d:callout" mode="enumerate-images">
1769 <!-- process arearefs to get name of callout bug image files -->
1770 <xsl:if test="$callout.graphics != 0">
1771 <xsl:variable name="arearefs">
1772 <xsl:call-template name="callout.arearefs">
1773 <xsl:with-param name="arearefs" select="@arearefs"/>
1774 </xsl:call-template>
1777 <xsl:variable name="nodes" select="exsl:node-set($arearefs)"/>
1779 <xsl:for-each select="$nodes//*[@src]">
1780 <xsl:variable name="image.filename" select="@src"/>
1782 <xsl:variable name="image.type">
1783 <xsl:call-template name="graphic.format.content-type">
1784 <xsl:with-param name="format" select="translate(
1785 substring-after($callout.graphics.extension,'.'),
1786 &lowercase;, &uppercase;)"/>
1787 </xsl:call-template>
1790 <xsl:element name="tmp-filename" namespace="">
1791 <xsl:element name="tmp-href" namespace="">
1792 <xsl:value-of select="$image.filename"/>
1794 <xsl:element name="media-type" namespace="">
1795 <xsl:value-of select="$image.type"/>
1803 <xsl:template match="d:co" mode="enumerate-images">
1804 <!-- process co to get name of callout bug image file -->
1805 <xsl:if test="$callout.graphics != 0">
1806 <xsl:variable name="result">
1807 <xsl:apply-templates select="." mode="callout-bug"/>
1810 <xsl:variable name="nodes" select="exsl:node-set($result)"/>
1812 <xsl:for-each select="$nodes//*[@src]">
1813 <xsl:variable name="image.filename" select="@src"/>
1815 <xsl:variable name="image.type">
1816 <xsl:call-template name="graphic.format.content-type">
1817 <xsl:with-param name="format" select="translate(
1818 substring-after($callout.graphics.extension,'.'),
1819 &lowercase;, &uppercase;)"/>
1820 </xsl:call-template>
1823 <xsl:element name="tmp-filename" namespace="">
1824 <xsl:element name="tmp-href" namespace="">
1825 <xsl:value-of select="$image.filename"/>
1827 <xsl:element name="media-type" namespace="">
1828 <xsl:value-of select="$image.type"/>
1837 <!-- ======================================================== -->
1838 <!-- NCX templates are for backwards compatibility with EPUB2 -->
1839 <!-- ======================================================== -->
1841 <xsl:template name="ncx">
1842 <xsl:message>Generating NCX file ...</xsl:message>
1843 <xsl:call-template name="write.chunk">
1844 <xsl:with-param name="filename">
1845 <xsl:value-of select="$epub.ncx.pathname" />
1847 <xsl:with-param name="method" select="'xml'" />
1848 <xsl:with-param name="encoding" select="'utf-8'" />
1849 <xsl:with-param name="indent" select="'no'" />
1850 <xsl:with-param name="quiet" select="$chunk.quietly" />
1851 <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
1852 <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
1853 <xsl:with-param name="content">
1854 <xsl:element name="ncx" namespace="{$ncx.namespace}">
1855 <xsl:attribute name="version">2005-1</xsl:attribute>
1857 <!-- Via Martin Goerner: On covers: the IDPF2.0 standard unfortunately does not have a provision for
1858 covers. We had to add one and we did so in conjunction with the IDPF and
1859 various publishers. The tag chosen to define the covers is:
1860 <meta name="cover" content="-reference to a manifest item-">
1861 Then, we also added a bit of logic to get rid cleanly of the HTML cover
1862 people usually add because the logical cover is not specced by the IDPF. So,
1863 if the HTML cover item is marked linear="no" AND there is a guide item of
1864 type="cover" pointing to it AND there is a logical cover specified in a
1865 <meta name="cover"> tag, THEN, the HTML cover is discarded. -->
1866 <xsl:element name="head" namespace="{$ncx.namespace}">
1867 <xsl:if test="/*/*[d:cover or contains(name(.), 'info')]//d:mediaobject[@role='cover' or ancestor::d:cover]">
1868 <xsl:element name="meta" namespace="{$ncx.namespace}">
1869 <xsl:attribute name="name">cover</xsl:attribute>
1870 <xsl:attribute name="content">
1871 <xsl:value-of select="$epub.cover.filename.id"/>
1875 <xsl:element name="meta" namespace="{$ncx.namespace}">
1876 <xsl:attribute name="name">dtb:uid</xsl:attribute>
1877 <xsl:attribute name="content"><xsl:call-template name="package-identifier"/></xsl:attribute>
1882 <xsl:when test="$rootid != ''">
1883 <xsl:variable name="title">
1884 <xsl:if test="$epub.autolabel != 0">
1885 <xsl:variable name="label.markup">
1886 <xsl:apply-templates select="key('id',$rootid)" mode="label.markup" />
1888 <xsl:if test="normalize-space($label.markup)">
1889 <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
1892 <xsl:apply-templates select="key('id',$rootid)" mode="title.markup" />
1894 <xsl:variable name="href">
1895 <xsl:call-template name="href.target.with.base.dir">
1896 <xsl:with-param name="object" select="key('id',$rootid)" />
1897 </xsl:call-template>
1899 <xsl:element name="docTitle" namespace="{$ncx.namespace}">
1900 <xsl:element name="text" namespace="{$ncx.namespace}"><xsl:value-of select="normalize-space($title)" /> </xsl:element>
1902 <xsl:element name="navMap" namespace="{$ncx.namespace}">
1903 <xsl:apply-templates select="key('id',$rootid)/*" mode="ncx" />
1907 <xsl:variable name="title">
1908 <xsl:if test="$epub.autolabel != 0">
1909 <xsl:variable name="label.markup">
1910 <xsl:apply-templates select="/*" mode="label.markup" />
1912 <xsl:if test="normalize-space($label.markup)">
1913 <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
1916 <xsl:apply-templates select="/*" mode="title.markup" />
1918 <xsl:variable name="href">
1919 <xsl:call-template name="href.target.with.base.dir">
1920 <xsl:with-param name="object" select="/" />
1921 </xsl:call-template>
1923 <xsl:element name="docTitle" namespace="{$ncx.namespace}">
1924 <xsl:element name="text" namespace="{$ncx.namespace}">
1925 <xsl:value-of select="normalize-space($title)" />
1928 <xsl:element name="navMap" namespace="{$ncx.namespace}">
1930 <xsl:when test="$root.is.a.chunk != '0'">
1931 <xsl:apply-templates select="/*" mode="ncx" />
1932 <xsl:apply-templates select="/*/*" mode="ncx" />
1935 <xsl:apply-templates select="/*/*" mode="ncx" />
1944 </xsl:call-template>
1947 <xsl:template match="d:book|
1965 d:bibliodiv[d:title]|
1969 <xsl:variable name="depth" select="count(ancestor::*)"/>
1970 <xsl:variable name="title">
1971 <xsl:if test="$epub.autolabel != 0">
1972 <xsl:variable name="label.markup">
1973 <xsl:apply-templates select="." mode="label.markup" />
1975 <xsl:if test="normalize-space($label.markup)">
1977 select="concat($label.markup,$autotoc.label.separator)" />
1980 <xsl:apply-templates select="." mode="title.markup" />
1983 <xsl:variable name="href">
1984 <xsl:call-template name="href.target.with.base.dir">
1985 <xsl:with-param name="context" select="/" />
1986 <!-- Generate links relative to the location of root file/toc.xml file -->
1987 </xsl:call-template>
1990 <xsl:variable name="id">
1991 <xsl:value-of select="generate-id(.)"/>
1993 <xsl:variable name="order">
1994 <xsl:value-of select="$depth +
1995 count(preceding::d:part|
1996 preceding::d:reference|
1997 preceding::d:book[parent::d:set]|
1998 preceding::d:preface|
1999 preceding::d:chapter|
2000 preceding::d:bibliography|
2001 preceding::d:appendix|
2002 preceding::d:article|
2004 preceding::d:glossary|
2005 preceding::d:section[not(parent::d:partintro)]|
2006 preceding::d:sect1[not(parent::d:partintro)]|
2007 preceding::d:sect2[not(ancestor::d:partintro)]|
2008 preceding::d:sect3[not(ancestor::d:partintro)]|
2009 preceding::d:sect4[not(ancestor::d:partintro)]|
2010 preceding::d:sect5[not(ancestor::d:partintro)]|
2011 preceding::d:refentry|
2012 preceding::d:colophon|
2013 preceding::d:bibliodiv[d:title]|
2014 preceding::d:index)"/>
2017 <xsl:element name="navPoint" namespace="{$ncx.namespace}">
2018 <xsl:attribute name="id">
2019 <xsl:value-of select="$id"/>
2022 <xsl:attribute name="playOrder">
2024 <xsl:when test="/*[self::d:set]">
2025 <xsl:value-of select="$order"/>
2027 <xsl:when test="$root.is.a.chunk != '0'">
2028 <xsl:value-of select="$order + 1"/>
2031 <xsl:value-of select="$order - 0"/>
2035 <xsl:element name="navLabel" namespace="{$ncx.namespace}">
2036 <xsl:element name="text" namespace="{$ncx.namespace}"><xsl:value-of select="normalize-space($title)"/> </xsl:element>
2038 <xsl:element name="content" namespace="{$ncx.namespace}">
2039 <xsl:attribute name="src">
2040 <xsl:value-of select="$href"/>
2043 <xsl:if test="$depth != 0">
2044 <!-- Don't recurse on root element, but treat it as a single point so
2045 the progress bar shows all top level children -->
2046 <xsl:apply-templates select="d:book[parent::d:set]|d:part|d:reference|d:preface|d:chapter|d:bibliography|d:appendix|d:article|d:topic|d:glossary|d:section|d:sect1|d:sect2|d:sect3|d:sect4|d:sect5|d:refentry|d:colophon|d:bibliodiv[d:title]|d:setindex|d:index" mode="ncx"/>
2052 <xsl:template match="text()" mode="ncx" />
2054 <xsl:template name="package.spine">
2056 <xsl:variable name="toc.params">
2057 <xsl:call-template name="find.path.params">
2058 <xsl:with-param name="node" select="."/>
2059 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
2060 </xsl:call-template>
2063 <xsl:element namespace="http://www.idpf.org/2007/opf" name="spine">
2064 <xsl:if test="$epub.include.ncx != 0">
2065 <xsl:attribute name="toc">
2066 <xsl:value-of select="$epub.ncx.manifest.id"/>
2070 <xsl:call-template name="spine.cover"/>
2073 <xsl:if test="contains($toc.params, 'toc')">
2074 <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
2075 <xsl:attribute name="idref"> <xsl:value-of select="$epub.html.toc.id"/> </xsl:attribute>
2076 <xsl:attribute name="linear">yes</xsl:attribute>
2080 <!-- TODO: be nice to have a idref="titlepage" here -->
2082 <xsl:when test="$root.is.a.chunk != '0'">
2083 <xsl:apply-templates select="/*" mode="package.spine"/>
2086 <xsl:apply-templates select="/*/*" mode="package.spine"/>
2093 <xsl:template name="spine.cover">
2094 <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
2095 <xsl:variable name="cover.image"
2096 select="$info//d:mediaobject[@role='cover' or ancestor::d:cover]"/>
2098 <xsl:if test="$cover.image">
2099 <!-- generate the spine reference to that cover html file -->
2100 <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
2101 <xsl:attribute name="idref">
2102 <xsl:value-of select="$epub.cover.filename.id"/>
2104 <xsl:attribute name="linear">
2106 <xsl:when test="$epub.cover.linear">
2107 <xsl:text>yes</xsl:text>
2109 <xsl:otherwise>no</xsl:otherwise>
2116 <xsl:template match="*" mode="package.spine">
2117 <xsl:variable name="is.chunk">
2118 <xsl:call-template name="chunk">
2119 <xsl:with-param name="node" select="."/>
2120 </xsl:call-template>
2123 <xsl:if test="$is.chunk != 0">
2124 <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
2125 <xsl:attribute name="idref">
2126 <xsl:value-of select="concat($epub.package.id.prefix, generate-id(.))"/>
2129 <xsl:apply-templates select="*|.//d:refentry" mode="package.spine"/>
2133 <xsl:template match="*" mode="container">
2134 <xsl:call-template name="container"/>
2137 <xsl:template name="container">
2138 <!-- The path in rootfile does not include all of base.dir, only the last part -->
2139 <xsl:variable name="full-path-dir">
2140 <xsl:call-template name="filename-basename">
2141 <xsl:with-param name="filename" select="$chunk.base.dir"/>
2142 </xsl:call-template>
2144 <xsl:call-template name="write.chunk">
2145 <xsl:with-param name="filename">
2146 <xsl:value-of select="$epub.container.pathname" />
2148 <xsl:with-param name="method" select="'xml'" />
2149 <xsl:with-param name="encoding" select="'utf-8'" />
2150 <xsl:with-param name="indent" select="'no'" />
2151 <xsl:with-param name="quiet" select="$chunk.quietly" />
2152 <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
2153 <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
2155 <xsl:with-param name="content">
2156 <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="container">
2157 <xsl:attribute name="version">1.0</xsl:attribute>
2158 <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="rootfiles">
2159 <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="rootfile">
2160 <xsl:attribute name="full-path">
2162 select="concat($full-path-dir, $epub.package.filename)"/>
2164 <xsl:attribute name="media-type">
2165 <xsl:text>application/oebps-package+xml</xsl:text>
2171 </xsl:call-template>
2174 <xsl:template name="mimetype">
2175 <xsl:call-template name="write.text.chunk">
2176 <xsl:with-param name="filename" select="$epub.mimetype.pathname"/>
2177 <xsl:with-param name="content" select="$epub.mimetype.value"/>
2178 </xsl:call-template>
2181 <xsl:template match="d:mediaobject[@role='cover' or ancestor::d:cover]">
2182 <xsl:call-template name="write.chunk">
2183 <xsl:with-param name="filename">
2184 <xsl:value-of select="$epub.cover.pathname" />
2186 <xsl:with-param name="method" select="'xml'" />
2187 <xsl:with-param name="encoding" select="'utf-8'" />
2188 <xsl:with-param name="indent" select="'no'" />
2189 <xsl:with-param name="quiet" select="$chunk.quietly" />
2190 <xsl:with-param name="content">
2191 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="html">
2192 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="head">
2193 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="title">Cover</xsl:element>
2194 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="style">
2195 <xsl:attribute name="type">text/css</xsl:attribute>
2196 <!-- Help the cover image scale nicely in the CSS then apply a max-width to look better in Adobe Digital Editions -->
2197 <xsl:text> img { max-width: 100%; }</xsl:text>
2200 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="body">
2201 <xsl:element namespace="http://www.w3.org/1999/xhtml" name="div">
2202 <xsl:attribute name="id">
2203 <xsl:value-of select="$epub.cover.image.id"/>
2206 <xsl:when test="d:imageobject[@role='front-large']">
2207 <xsl:apply-templates select="d:imageobject[@role='front-large']"/>
2210 <xsl:apply-templates select="d:imageobject[1]"/>
2214 <!-- If this is defined as an explicit cover page, then process
2215 any remaining text -->
2216 <xsl:if test="ancestor::d:cover">
2217 <xsl:apply-templates select="ancestor::d:cover/d:para"/>
2222 </xsl:call-template>
2225 <!-- EPUB3: use <nav> and <ol> in TOC lists -->
2226 <xsl:template name="make.toc">
2227 <xsl:param name="toc-context" select="."/>
2228 <xsl:param name="toc.title.p" select="true()"/>
2229 <xsl:param name="nodes" select="/NOT-AN-ELEMENT"/>
2231 <xsl:variable name="nodes.plus" select="$nodes | d:qandaset"/>
2233 <xsl:variable name="toc.title">
2234 <xsl:if test="$toc.title.p">
2236 <xsl:when test="$make.clean.html != 0">
2237 <div class="toc-title">
2238 <xsl:call-template name="gentext">
2239 <xsl:with-param name="key">TableofContents</xsl:with-param>
2240 </xsl:call-template>
2246 <xsl:call-template name="gentext">
2247 <xsl:with-param name="key">TableofContents</xsl:with-param>
2248 </xsl:call-template>
2257 <xsl:when test="$manual.toc != ''">
2258 <xsl:variable name="id">
2259 <xsl:call-template name="object.id"/>
2261 <xsl:variable name="toc" select="document($manual.toc, .)"/>
2262 <xsl:variable name="tocentry" select="$toc//d:tocentry[@linkend=$id]"/>
2263 <xsl:if test="$tocentry and $tocentry/*">
2265 <xsl:copy-of select="$toc.title"/>
2266 <nav epub:type="toc">
2267 <xsl:element name="{$toc.list.type}">
2268 <xsl:call-template name="manual-toc">
2269 <xsl:with-param name="tocentry" select="$tocentry/*[1]"/>
2270 </xsl:call-template>
2278 <xsl:when test="$qanda.in.toc != 0">
2280 <xsl:copy-of select="$toc.title"/>
2281 <nav epub:type="toc">
2282 <xsl:element name="{$toc.list.type}">
2283 <xsl:if test="$nodes.plus">
2284 <xsl:apply-templates select="$nodes.plus" mode="toc">
2285 <xsl:with-param name="toc-context" select="$toc-context"/>
2286 </xsl:apply-templates>
2294 <xsl:copy-of select="$toc.title"/>
2295 <nav epub:type="toc">
2296 <xsl:element name="{$toc.list.type}">
2297 <xsl:if test="$nodes">
2298 <xsl:apply-templates select="$nodes" mode="toc">
2299 <xsl:with-param name="toc-context" select="$toc-context"/>
2300 </xsl:apply-templates>
2312 <xsl:template name="list.of.titles">
2313 <xsl:param name="toc-context" select="."/>
2314 <xsl:param name="titles" select="'table'"/>
2315 <xsl:param name="nodes" select=".//d:table"/>
2317 <xsl:variable name="epub.type">
2319 <xsl:when test="$titles='table'">lot</xsl:when>
2320 <xsl:when test="$titles='figure'">loi</xsl:when>
2321 <xsl:when test="$titles='equation'">loi</xsl:when>
2322 <xsl:when test="$titles='example'">loi</xsl:when>
2323 <xsl:when test="$titles='procedure'">loi</xsl:when>
2324 <xsl:otherwise>loi</xsl:otherwise>
2328 <xsl:if test="$nodes">
2329 <div class="list-of-{$titles}s">
2330 <nav epub:type="{$epub.type}">
2331 <h4 class="toc-title">
2332 <xsl:call-template name="gentext">
2333 <xsl:with-param name="key">
2335 <xsl:when test="$titles='table'">ListofTables</xsl:when>
2336 <xsl:when test="$titles='figure'">ListofFigures</xsl:when>
2337 <xsl:when test="$titles='equation'">ListofEquations</xsl:when>
2338 <xsl:when test="$titles='example'">ListofExamples</xsl:when>
2339 <xsl:when test="$titles='procedure'">ListofProcedures</xsl:when>
2340 <xsl:otherwise>ListofUnknown</xsl:otherwise>
2343 </xsl:call-template>
2346 <xsl:element name="{$toc.list.type}">
2347 <xsl:apply-templates select="$nodes" mode="toc">
2348 <xsl:with-param name="toc-context" select="$toc-context"/>
2349 </xsl:apply-templates>
2356 <!-- EPUB3: add hidden="" for sections below toc.section.depth -->
2357 <xsl:template name="subtoc">
2358 <xsl:param name="toc-context" select="."/>
2359 <xsl:param name="nodes" select="NOT-AN-ELEMENT"/>
2361 <xsl:variable name="nodes.plus" select="$nodes | d:qandaset"/>
2363 <xsl:variable name="depth">
2365 <xsl:when test="local-name(.) = 'section'">
2366 <xsl:value-of select="count(ancestor::d:section) + 1"/>
2368 <xsl:when test="local-name(.) = 'sect1'">1</xsl:when>
2369 <xsl:when test="local-name(.) = 'sect2'">2</xsl:when>
2370 <xsl:when test="local-name(.) = 'sect3'">3</xsl:when>
2371 <xsl:when test="local-name(.) = 'sect4'">4</xsl:when>
2372 <xsl:when test="local-name(.) = 'sect5'">5</xsl:when>
2373 <xsl:when test="local-name(.) = 'refsect1'">1</xsl:when>
2374 <xsl:when test="local-name(.) = 'refsect2'">2</xsl:when>
2375 <xsl:when test="local-name(.) = 'refsect3'">3</xsl:when>
2376 <xsl:when test="local-name(.) = 'simplesect'">
2379 <xsl:when test="local-name(..) = 'section'">
2380 <xsl:value-of select="count(ancestor::d:section)"/>
2382 <xsl:when test="local-name(..) = 'sect1'">2</xsl:when>
2383 <xsl:when test="local-name(..) = 'sect2'">3</xsl:when>
2384 <xsl:when test="local-name(..) = 'sect3'">4</xsl:when>
2385 <xsl:when test="local-name(..) = 'sect4'">5</xsl:when>
2386 <xsl:when test="local-name(..) = 'sect5'">6</xsl:when>
2387 <xsl:when test="local-name(..) = 'refsect1'">2</xsl:when>
2388 <xsl:when test="local-name(..) = 'refsect2'">3</xsl:when>
2389 <xsl:when test="local-name(..) = 'refsect3'">4</xsl:when>
2390 <xsl:otherwise>1</xsl:otherwise>
2393 <xsl:otherwise>0</xsl:otherwise>
2397 <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
2399 <xsl:variable name="subtoc">
2400 <xsl:element name="{$toc.list.type}">
2402 <xsl:when test="$toc.listitem.type = 'li'
2403 and $toc.section.depth > $depth and
2404 ( ($qanda.in.toc = 0 and count($nodes)>0) or
2405 ($qanda.in.toc != 0 and count($nodes.plus)>0) )
2406 and $toc.max.depth > $depth.from.context">
2407 <!-- No @hidden attribute -->
2410 <!-- Add empty @hidden attribute if too deep -->
2411 <xsl:attribute name="hidden"></xsl:attribute>
2416 <xsl:when test="$qanda.in.toc != 0">
2417 <xsl:apply-templates mode="toc" select="$nodes.plus">
2418 <xsl:with-param name="toc-context" select="$toc-context"/>
2419 </xsl:apply-templates>
2422 <xsl:apply-templates mode="toc" select="$nodes">
2423 <xsl:with-param name="toc-context" select="$toc-context"/>
2424 </xsl:apply-templates>
2430 <xsl:variable name="subtoc.list">
2432 <xsl:when test="$toc.dd.type = ''">
2433 <xsl:copy-of select="$subtoc"/>
2436 <xsl:element name="{$toc.dd.type}">
2437 <xsl:copy-of select="$subtoc"/>
2443 <xsl:element name="{$toc.listitem.type}">
2444 <xsl:call-template name="toc.line">
2445 <xsl:with-param name="toc-context" select="$toc-context"/>
2446 </xsl:call-template>
2447 <xsl:if test="$toc.listitem.type = 'li'
2449 ( ($qanda.in.toc = 0 and count($nodes)>0) or
2450 ($qanda.in.toc != 0 and count($nodes.plus)>0) ) ">
2451 <xsl:copy-of select="$subtoc.list"/>
2456 <!-- Inserted when a title is blank to avoid epubcheck error -->
2457 <xsl:param name="toc.entry.default.text"> </xsl:param>
2459 <!-- EPUB3: either <a> or <span>, but not both -->
2460 <xsl:template name="toc.line">
2461 <xsl:param name="toc-context" select="."/>
2462 <xsl:param name="depth" select="1"/>
2463 <xsl:param name="depth.from.context" select="8"/>
2465 <xsl:variable name="title">
2466 <xsl:apply-templates select="." mode="title.markup"/>
2470 <xsl:attribute name="href">
2471 <xsl:call-template name="href.target">
2472 <xsl:with-param name="context" select="$toc-context"/>
2473 <xsl:with-param name="toc-context" select="$toc-context"/>
2474 </xsl:call-template>
2477 <!-- * if $autotoc.label.in.hyperlink is non-zero, then output the label -->
2478 <!-- * as part of the hyperlinked title -->
2479 <xsl:if test="not($autotoc.label.in.hyperlink = 0)">
2480 <xsl:variable name="label">
2481 <xsl:apply-templates select="." mode="label.markup"/>
2483 <xsl:copy-of select="$label"/>
2484 <xsl:if test="$label != ''">
2485 <xsl:value-of select="$autotoc.label.separator"/>
2490 <xsl:when test="string-length(normalize-space($title)) != 0">
2491 <xsl:copy-of select="$title"/>
2494 <xsl:value-of select="$toc.entry.default.text"/>
2500 <!-- Make sure all text is inside the <a> element for epub3 -->
2501 <xsl:template match="d:figure|d:table|d:example|d:equation|d:procedure" mode="toc">
2502 <xsl:param name="toc-context" select="."/>
2504 <xsl:element name="{$toc.listitem.type}">
2506 <xsl:attribute name="href">
2507 <xsl:call-template name="href.target">
2508 <xsl:with-param name="toc-context" select="$toc-context"/>
2509 </xsl:call-template>
2511 <xsl:variable name="label">
2512 <xsl:apply-templates select="." mode="label.markup"/>
2514 <xsl:copy-of select="$label"/>
2515 <xsl:if test="$label != ''">
2516 <xsl:value-of select="$autotoc.label.separator"/>
2518 <xsl:apply-templates select="." mode="titleabbrev.markup"/>
2523 <!-- Remove spans from refentry TOC lines for epub3check -->
2524 <xsl:template match="d:refentry" mode="toc">
2525 <xsl:param name="toc-context" select="."/>
2527 <xsl:variable name="refmeta" select=".//d:refmeta"/>
2528 <xsl:variable name="refentrytitle" select="$refmeta//d:refentrytitle"/>
2529 <xsl:variable name="refnamediv" select=".//d:refnamediv"/>
2530 <xsl:variable name="refname" select="$refnamediv//d:refname"/>
2531 <xsl:variable name="refdesc" select="$refnamediv//d:refdescriptor"/>
2532 <xsl:variable name="title">
2534 <xsl:when test="$refentrytitle">
2535 <xsl:apply-templates select="$refentrytitle[1]" mode="titleabbrev.markup"/>
2537 <xsl:when test="$refdesc">
2538 <xsl:apply-templates select="$refdesc" mode="titleabbrev.markup"/>
2540 <xsl:when test="$refname">
2541 <xsl:apply-templates select="$refname[1]" mode="titleabbrev.markup"/>
2546 <xsl:element name="{$toc.listitem.type}" namespace="http://www.w3.org/1999/xhtml">
2548 <xsl:attribute name="href">
2549 <xsl:call-template name="href.target">
2550 <xsl:with-param name="toc-context" select="$toc-context"/>
2551 </xsl:call-template>
2553 <xsl:copy-of select="$title"/>
2554 <xsl:if test="$annotate.toc != 0">
2555 <!-- * DocBook 5 says inlinemediaobject (among other things) -->
2556 <!-- * is allowed in refpurpose; so we need to run -->
2557 <!-- * apply-templates on refpurpose here, instead of value-of -->
2558 <!-- Set allow-anchors=0 to avoid indexterms and other links -->
2559 <xsl:text> - </xsl:text>
2560 <xsl:apply-templates select="d:refnamediv/d:refpurpose" mode="no.anchor.mode"/>
2566 <!-- Copy these here so relative document() open gets the correct css source -->
2567 <xsl:template name="generate.default.css.file">
2568 <xsl:if test="$make.clean.html != 0 and
2569 $generate.css.header = 0 and
2570 $docbook.css.source != ''">
2571 <!-- Select default file relative to stylesheet -->
2572 <xsl:variable name="css.node" select="document($docbook.css.source)/*[1]"/>
2574 <xsl:call-template name="generate.css.file">
2575 <xsl:with-param name="src" select="$docbook.css.source"/>
2576 <xsl:with-param name="css.node" select="$css.node"/>
2577 </xsl:call-template>
2581 <xsl:template name="generate.custom.css.file">
2582 <xsl:if test="$custom.css.source != '' and
2583 $generate.css.header = 0">
2584 <!-- Select custom file relative to document -->
2585 <xsl:variable name="css.node" select="document($custom.css.source,.)/*[1]"/>
2587 <xsl:call-template name="generate.css.file">
2588 <xsl:with-param name="src" select="$custom.css.source"/>
2589 <xsl:with-param name="css.node" select="$css.node"/>
2590 </xsl:call-template>