epub3-element-mods.xsl 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE xsl:stylesheet [
  3. <!ENTITY uppercase "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'">
  4. <!ENTITY lowercase "'abcdefghijklmnopqrstuvwxyz'">
  5. ]>
  6. <xsl:stylesheet
  7. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  8. xmlns:exsl="http://exslt.org/common"
  9. xmlns:set="http://exslt.org/sets"
  10. xmlns="http://www.w3.org/1999/xhtml"
  11. xmlns:epub="http://www.idpf.org/2007/ops"
  12. xmlns:m="http://www.w3.org/1998/Math/MathML"
  13. xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon"
  14. xmlns:ssml="http://www.w3.org/2001/10/synthesis"
  15. xmlns:svg="http://www.w3.org/2000/svg"
  16. xmlns:opf="http://www.idpf.org/2007/opf"
  17. xmlns:dc="http://purl.org/dc/elements/1.1/"
  18. xmlns:cf="http://docbook.sourceforge.net/xmlns/chunkfast/1.0"
  19. xmlns:date="http://exslt.org/dates-and-times"
  20. xmlns:dcterms="http://purl.org/dc/terms/"
  21. xmlns:ncx="http://www.daisy.org/z3986/2005/ncx/"
  22. xmlns:db="http://docbook.org/ns/docbook"
  23. xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
  24. xmlns:str="http://exslt.org/strings"
  25. xmlns:xtext="xalan://com.nwalsh.xalan.Text"
  26. extension-element-prefixes="stext xtext"
  27. exclude-result-prefixes="#default cf date db dc dcterms epub exsl m ncx opf pls set ssml stext str svg xtext"
  28. version="1.0">
  29. <!-- $Id: epub3-element-mods.xsl,v 1.1 2011-09-16 21:43:45 bobs Exp $ -->
  30. <xsl:import href="titlepage.templates.xsl"/>
  31. <!--
  32. <xsl:key name="image-filerefs" match="graphic|inlinegraphic|imagedata" use="@fileref"/>
  33. -->
  34. <!--==============================================================-->
  35. <!-- DocBook XSL Parameter settings -->
  36. <!--==============================================================-->
  37. <!-- separate file for toc -->
  38. <xsl:param name="chunk.tocs.and.lots" select="1"/>
  39. <xsl:param name="toc.section.depth" select="2"/>
  40. <xsl:param name="generate.toc">
  41. book toc,title,figure,table,example,equation
  42. article toc,title,figure,table,example,equation
  43. </xsl:param>
  44. <xsl:param name="generate.manifest" select="0"/>
  45. <xsl:param name="manifest.in.base.dir" select="1"/>
  46. <xsl:param name="base.dir" select="'OEBPS/'"/>
  47. <xsl:param name="index.links.to.section" select="0"/>
  48. <!-- Epub does not yet support external links -->
  49. <xsl:param name="activate.external.olinks" select="0"/>
  50. <!-- Turning this on crashes ADE, which is unbelievably awesome -->
  51. <xsl:param name="formal.object.break.after">0</xsl:param>
  52. <xsl:param name="callout.graphics" select="1"/>
  53. <xsl:param name="callout.graphics.extension">.png</xsl:param>
  54. <xsl:param name="callout.graphics.number.limit" select="15"/>
  55. <xsl:param name="callout.graphics.path" select="'images/callouts/'"/>
  56. <xsl:param name="show.comments" select="0"/>
  57. <!-- no navigation in .epub -->
  58. <xsl:param name="suppress.navigation" select="'1'"/>
  59. <!-- EPUB3: use ol lists in table of contents -->
  60. <xsl:param name="toc.list.type">ol</xsl:param>
  61. <xsl:param name="autotoc.label.in.hyperlink" select="1"/>
  62. <xsl:param name="css.decoration" select="1"/>
  63. <!-- generate the css file from a source file -->
  64. <xsl:param name="make.clean.html" select="1"/>
  65. <!-- specify the default epub3 stylesheet -->
  66. <xsl:param name="docbook.css.source">docbook-epub.css.xml</xsl:param>
  67. <!-- for custom CSS, use the custom.css.source param -->
  68. <xsl:param name="custom.css.source"></xsl:param>
  69. <!--==============================================================-->
  70. <!-- New EPUB3 Parameters -->
  71. <!--==============================================================-->
  72. <xsl:param name="epub.version">3.0</xsl:param>
  73. <!-- optional ncx for backwards compatibility -->
  74. <xsl:param name="epub.include.ncx" select="1"/>
  75. <xsl:param name="epub.ncx.depth">4</xsl:param> <!-- Not functional until http://code.google.com/p/epubcheck/issues/detail?id=70 is resolved -->
  76. <!-- currently optional duplicate dcterms properties, may be required in future -->
  77. <xsl:param name="epub.include.metadata.dcterms" select="1"/>
  78. <!-- optional guide element for backwards compatibility -->
  79. <xsl:param name="epub.include.guide" select="1"/>
  80. <!-- some dc: currently required, to be replaced in future version -->
  81. <xsl:param name="epub.include.metadata.dc.elements" select="1"/>
  82. <!-- Some dc: elements will remain optional according to the spec -->
  83. <xsl:param name="epub.include.optional.metadata.dc.elements" select="1"/>
  84. <xsl:param name="epub.autolabel" select="0"/>
  85. <xsl:param
  86. name="epub.vocabulary.profile.content">http://www.idpf.org/epub/30/profile/content/</xsl:param>
  87. <xsl:param
  88. name="epub.vocabulary.profile.package">http://www.idpf.org/epub/30/profile/package/</xsl:param>
  89. <xsl:param name="epub.output.epub.types" select="1"/>
  90. <xsl:param name="epub.oebps.dir" select="'OEBPS'"/>
  91. <xsl:param name="epub.metainf.dir" select="'META-INF/'"/>
  92. <xsl:param name="epub.ncx.filename" select="'toc.ncx'"/>
  93. <xsl:param name="epub.mimetype.filename" select="'mimetype'"/>
  94. <xsl:param name="epub.mimetype.value" select="'application/epub+zip'"/>
  95. <xsl:param name="epub.container.filename" select="'container.xml'"/>
  96. <xsl:param name="epub.package.filename" select="'package.opf'"/>
  97. <xsl:param name="epub.cover.filename" select="concat('cover', $html.ext)"/>
  98. <xsl:param name="epub.cover.linear" select="0" />
  99. <!-- names of id attributes used in package files -->
  100. <xsl:param name="epub.meta.identifier.id">meta-identifier</xsl:param>
  101. <xsl:param name="epub.dc.identifier.id">pub-identifier</xsl:param>
  102. <xsl:param name="epub.meta.title.id">meta-title</xsl:param>
  103. <xsl:param name="epub.dc.title.id">pub-title</xsl:param>
  104. <xsl:param name="epub.meta.language.id">meta-language</xsl:param>
  105. <xsl:param name="epub.dc.language.id">pub-language</xsl:param>
  106. <xsl:param name="epub.meta.creator.id">meta-creator</xsl:param>
  107. <xsl:param name="epub.dc.creator.id">pub-creator</xsl:param>
  108. <xsl:param name="epub.ncx.toc.id">ncxtoc</xsl:param>
  109. <xsl:param name="epub.ncx.manifest.id">ncx</xsl:param>
  110. <xsl:param name="epub.ncx.mediatype">application/x-dtbncx+xml</xsl:param>
  111. <xsl:param name="epub.xhtml.mediatype">application/xhtml+xml</xsl:param>
  112. <xsl:param name="epub.html.toc.id">htmltoc</xsl:param>
  113. <xsl:param name="epub.cover.filename.id" select="'cover'"/>
  114. <xsl:param name="epub.cover.image.id" select="'cover-image'"/>
  115. <xsl:param name="epub.embedded.fonts"></xsl:param>
  116. <xsl:param name="epub.namespace">http://www.idpf.org/2007/ops</xsl:param>
  117. <xsl:param name="opf.namespace">http://www.idpf.org/2007/opf</xsl:param>
  118. <xsl:param name="ncx.namespace">http://www.daisy.org/z3986/2005/ncx/</xsl:param>
  119. <xsl:param name="dc.namespace">http://purl.org/dc/elements/1.1/</xsl:param>
  120. <!-- prefix generated ids in package elements so they differ from content ids -->
  121. <xsl:param name="epub.package.id.prefix">id-</xsl:param>
  122. <!-- editor is either a creator or contributor -->
  123. <xsl:param name="editor.property">contributor</xsl:param>
  124. <!-- Generate full output path -->
  125. <xsl:param name="epub.package.dir" select="concat($chunk.base.dir, '../')"/>
  126. <xsl:param name="epub.ncx.pathname"
  127. select="concat($chunk.base.dir, $epub.ncx.filename)"/>
  128. <xsl:param name="epub.container.pathname"
  129. select="concat($epub.package.dir, $epub.metainf.dir,
  130. $epub.container.filename)"/>
  131. <xsl:param name="epub.package.pathname"
  132. select="concat($chunk.base.dir, $epub.package.filename)"/>
  133. <xsl:param name="epub.cover.pathname"
  134. select="concat($chunk.base.dir, $epub.cover.filename)"/>
  135. <xsl:param name="epub.mimetype.pathname"
  136. select="concat($epub.package.dir, $epub.mimetype.filename)"/>
  137. <xsl:param name="kindle.extensions" select="0"/>
  138. <!--==============================================================-->
  139. <!-- Internal variables used for computing certain metadata -->
  140. <!--==============================================================-->
  141. <xsl:variable name="epub3.chunk.hierarchy">
  142. <xsl:apply-templates select="/*" mode="find.chunks"/>
  143. </xsl:variable>
  144. <xsl:variable name="chunkset" select="exsl:node-set($epub3.chunk.hierarchy)//cf:div"/>
  145. <!--==============================================================-->
  146. <!-- Template customizations -->
  147. <!--==============================================================-->
  148. <!-- This is used only by ncx piece -->
  149. <xsl:variable name="root.is.a.chunk">
  150. <xsl:choose>
  151. <xsl:when test="/*[not(self::book)][not(sect1) or not(section)]">
  152. <xsl:text>1</xsl:text>
  153. </xsl:when>
  154. <xsl:when test="/book[*[last()][self::bookinfo]]|book[bookinfo]">
  155. <xsl:text>1</xsl:text>
  156. </xsl:when>
  157. <xsl:when test="/book[*[last()][self::info]]|book[info]">
  158. <xsl:text>1</xsl:text>
  159. </xsl:when>
  160. <xsl:when test="/bibliography">
  161. <xsl:text>1</xsl:text>
  162. </xsl:when>
  163. <xsl:otherwise>
  164. <xsl:text>0</xsl:text>
  165. </xsl:otherwise>
  166. </xsl:choose>
  167. </xsl:variable>
  168. <!-- EPUB3: Add generation of epub publication files -->
  169. <xsl:template match="*" mode="process.root">
  170. <xsl:variable name="doc" select="self::*"/>
  171. <xsl:call-template name="user.preroot"/>
  172. <xsl:call-template name="root.messages"/>
  173. <html>
  174. <head>
  175. <xsl:call-template name="system.head.content">
  176. <xsl:with-param name="node" select="$doc"/>
  177. </xsl:call-template>
  178. <xsl:call-template name="head.content">
  179. <xsl:with-param name="node" select="$doc"/>
  180. </xsl:call-template>
  181. <xsl:call-template name="user.head.content">
  182. <xsl:with-param name="node" select="$doc"/>
  183. </xsl:call-template>
  184. </head>
  185. <body>
  186. <xsl:call-template name="body.attributes"/>
  187. <xsl:call-template name="user.header.content">
  188. <xsl:with-param name="node" select="$doc"/>
  189. </xsl:call-template>
  190. <xsl:apply-templates select="."/>
  191. <xsl:call-template name="user.footer.content">
  192. <xsl:with-param name="node" select="$doc"/>
  193. </xsl:call-template>
  194. </body>
  195. </html>
  196. <xsl:value-of select="$html.append"/>
  197. <!-- Generate any css files only once, not once per chunk -->
  198. <xsl:call-template name="generate.css.files"/>
  199. <xsl:call-template name="generate.epub.files"/>
  200. </xsl:template>
  201. <xsl:template name="generate.epub.files">
  202. <!-- Generate epub3 files -->
  203. <xsl:message>
  204. <xsl:text>Generating EPUB package files.</xsl:text>
  205. </xsl:message>
  206. <xsl:apply-templates select="." mode="opf"/>
  207. <xsl:apply-templates select="." mode="container"/>
  208. <xsl:call-template name="mimetype"/>
  209. <xsl:if test="$epub.include.ncx != 0">
  210. <xsl:call-template name="ncx"/>
  211. </xsl:if>
  212. </xsl:template>
  213. <!-- Generate the package file -->
  214. <xsl:template match="*" mode="opf">
  215. <xsl:variable name="lang">
  216. <xsl:call-template name="l10n.language"/>
  217. </xsl:variable>
  218. <xsl:variable name="content">
  219. <!-- use xsl:element so output does not have a namespace prefix -->
  220. <xsl:element name="package" namespace="{$opf.namespace}">
  221. <!-- Add the package namespaces at the top -->
  222. <xsl:call-template name="add.package.namespaces"/>
  223. <xsl:attribute name="version">
  224. <xsl:value-of select="$epub.version"/>
  225. </xsl:attribute>
  226. <xsl:attribute name="xml:lang">
  227. <xsl:value-of select="$lang"/>
  228. </xsl:attribute>
  229. <!-- No profile att in 2011-09-06 spec
  230. <xsl:attribute name="profile">
  231. <xsl:value-of select="$epub.vocabulary.profile.package"/>
  232. </xsl:attribute>
  233. -->
  234. <xsl:attribute name="unique-identifier">
  235. <xsl:value-of select="$epub.dc.identifier.id"/>
  236. </xsl:attribute>
  237. <xsl:call-template name="package.metadata"/>
  238. <xsl:call-template name="package.manifest"/>
  239. <xsl:call-template name="package.spine"/>
  240. <xsl:if test="$epub.include.guide != 0">
  241. <xsl:call-template name="package.guide"/>
  242. </xsl:if>
  243. </xsl:element>
  244. </xsl:variable>
  245. <xsl:call-template name="write.chunk">
  246. <xsl:with-param name="filename">
  247. <xsl:value-of select="$epub.package.pathname" />
  248. </xsl:with-param>
  249. <xsl:with-param name="content" select="$content"/>
  250. <xsl:with-param name="method" select="'xml'" />
  251. <xsl:with-param name="encoding" select="'utf-8'" />
  252. <xsl:with-param name="indent" select="'yes'" />
  253. <xsl:with-param name="quiet" select="$chunk.quietly" />
  254. <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
  255. <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
  256. </xsl:call-template>
  257. </xsl:template>
  258. <xsl:template name="package.metadata">
  259. <xsl:element name="metadata" namespace="{$opf.namespace}">
  260. <xsl:call-template name="metadata.identifier"/>
  261. <xsl:call-template name="metadata.title"/>
  262. <xsl:call-template name="metadata.language"/>
  263. <xsl:call-template name="metadata.modified"/>
  264. <xsl:call-template name="metadata.cover"/>
  265. <xsl:call-template name="metadata.other.info"/>
  266. </xsl:element>
  267. </xsl:template>
  268. <xsl:template name="doc.title">
  269. <xsl:apply-templates select="." mode="title.markup"/>
  270. </xsl:template>
  271. <xsl:template name="metadata.identifier">
  272. <xsl:variable name="package.id.value">
  273. <xsl:call-template name="package-identifier"/>
  274. </xsl:variable>
  275. <xsl:if test="$epub.include.metadata.dc.elements != 0">
  276. <!-- dc:identifier element -->
  277. <dc:identifier>
  278. <xsl:attribute name="id">
  279. <xsl:value-of select="$epub.dc.identifier.id"/>
  280. </xsl:attribute>
  281. <!--
  282. <xsl:attribute name="prefer">
  283. <xsl:value-of select="$epub.meta.identifier.id"/>
  284. </xsl:attribute>
  285. -->
  286. <xsl:copy-of select="$package.id.value"/>
  287. </dc:identifier>
  288. </xsl:if>
  289. <xsl:if test="$epub.include.metadata.dcterms != 0">
  290. <!-- equivalent meta identifier element -->
  291. <xsl:element name="meta" namespace="{$opf.namespace}">
  292. <xsl:attribute name="id">
  293. <xsl:value-of select="$epub.meta.identifier.id"/>
  294. </xsl:attribute>
  295. <xsl:attribute name="property">dcterms:identifier</xsl:attribute>
  296. <xsl:copy-of select="$package.id.value"/>
  297. </xsl:element>
  298. </xsl:if>
  299. </xsl:template>
  300. <xsl:template name="metadata.title">
  301. <xsl:variable name="doc.title">
  302. <xsl:call-template name="doc.title"/>
  303. </xsl:variable>
  304. <xsl:if test="$epub.include.metadata.dc.elements != 0">
  305. <dc:title>
  306. <xsl:attribute name="id">
  307. <xsl:value-of select="$epub.dc.title.id"/>
  308. </xsl:attribute>
  309. <!--
  310. <xsl:attribute name="prefer">
  311. <xsl:value-of select="$epub.meta.title.id"/>
  312. </xsl:attribute>
  313. -->
  314. <xsl:value-of select="normalize-space($doc.title)"/>
  315. </dc:title>
  316. </xsl:if>
  317. <xsl:if test="$epub.include.metadata.dcterms != 0">
  318. <!-- equivalent meta title element -->
  319. <xsl:element name="meta" namespace="{$opf.namespace}">
  320. <xsl:attribute name="property">dcterms:title</xsl:attribute>
  321. <xsl:attribute name="id">
  322. <xsl:value-of select="$epub.meta.title.id"/>
  323. </xsl:attribute>
  324. <xsl:value-of select="normalize-space($doc.title)"/>
  325. </xsl:element>
  326. </xsl:if>
  327. </xsl:template>
  328. <xsl:template name="metadata.language">
  329. <xsl:variable name="lang">
  330. <xsl:call-template name="l10n.language"/>
  331. </xsl:variable>
  332. <xsl:if test="$epub.include.metadata.dc.elements != 0">
  333. <dc:language>
  334. <xsl:if test="$kindle.extensions = 0">
  335. <xsl:attribute name="id">
  336. <xsl:value-of select="$epub.dc.language.id"/>
  337. </xsl:attribute>
  338. </xsl:if>
  339. <xsl:value-of select="$lang"/>
  340. </dc:language>
  341. </xsl:if>
  342. <xsl:if test="$epub.include.metadata.dcterms != 0">
  343. <!-- equivalent meta lang element -->
  344. <xsl:element name="meta" namespace="{$opf.namespace}">
  345. <xsl:attribute name="property">dcterms:language</xsl:attribute>
  346. <xsl:attribute name="id">
  347. <xsl:value-of select="$epub.meta.language.id"/>
  348. </xsl:attribute>
  349. <xsl:value-of select="$lang"/>
  350. </xsl:element>
  351. </xsl:if>
  352. </xsl:template>
  353. <xsl:template name="metadata.modified">
  354. <xsl:variable name="local.datetime" select="date:date-time()"/>
  355. <xsl:variable name="utc.datetime">
  356. <xsl:call-template name="convert.date.to.utc">
  357. <xsl:with-param name="date" select="$local.datetime"/>
  358. </xsl:call-template>
  359. </xsl:variable>
  360. <xsl:choose>
  361. <xsl:when test="string-length($utc.datetime) != 0">
  362. <xsl:element name="meta" namespace="{$opf.namespace}">
  363. <xsl:attribute name="property">dcterms:modified</xsl:attribute>
  364. <xsl:value-of select="$utc.datetime"/>
  365. </xsl:element>
  366. <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>
  367. </xsl:when>
  368. <xsl:otherwise>
  369. <xsl:message terminate="yes">
  370. <xsl:text>ERROR: no last-modified date value could be determined, </xsl:text>
  371. <xsl:text>so cannot output required meta element with </xsl:text>
  372. <xsl:text>dcterms:modified attribute. Exiting.</xsl:text>
  373. </xsl:message>
  374. </xsl:otherwise>
  375. </xsl:choose>
  376. </xsl:template>
  377. <xsl:template name="convert.date.to.utc">
  378. <xsl:param name="date" select="''"/>
  379. <!-- input format is YYYY-MM-DDTHH:MM:SS-X:00
  380. where -X:00 is the offset from UTC. -->
  381. <!-- output format is YYYY-MM-DDTHH:MM:SSZ with no offset -->
  382. <!-- FIX ME: Not so easy without a proper UTC date function. -->
  383. <!-- Currently it just converts the local time to this format, which is
  384. not the correct UTC time. -->
  385. <xsl:value-of select="concat(substring($date,1,19), 'Z')"/>
  386. </xsl:template>
  387. <!-- This cover meta element used by kindlegen, at least -->
  388. <xsl:template name="metadata.cover">
  389. <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
  390. <xsl:variable name="cover.image"
  391. select="$info//mediaobject[@role='cover' or ancestor::cover]"/>
  392. <xsl:if test="$cover.image">
  393. <xsl:element name="meta" namespace="{$opf.namespace}">
  394. <xsl:attribute name="content">
  395. <xsl:value-of select="$epub.cover.image.id"/>
  396. </xsl:attribute>
  397. <xsl:attribute name="name">cover</xsl:attribute>
  398. </xsl:element>
  399. </xsl:if>
  400. </xsl:template>
  401. <xsl:template name="metadata.other.info">
  402. <!-- Take info relative to selected root element -->
  403. <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
  404. <xsl:apply-templates select="$info/*" mode="opf.metadata"/>
  405. </xsl:template>
  406. <xsl:template match="*" mode="opf.metadata">
  407. <!-- default is no output -->
  408. </xsl:template>
  409. <xsl:template match="authorgroup" mode="opf.metadata">
  410. <xsl:apply-templates select="*" mode="opf.metadata"/>
  411. </xsl:template>
  412. <xsl:template match="author|corpauthor" mode="opf.metadata">
  413. <xsl:variable name="n">
  414. <xsl:choose>
  415. <xsl:when test="self::corpauthor">
  416. <xsl:apply-templates/>
  417. </xsl:when>
  418. <xsl:when test="org/orgname">
  419. <xsl:apply-templates select="org/orgname"/>
  420. </xsl:when>
  421. <xsl:when test="orgname">
  422. <xsl:apply-templates select="orgname"/>
  423. </xsl:when>
  424. <xsl:otherwise>
  425. <xsl:call-template name="person.name">
  426. <xsl:with-param name="node" select="."/>
  427. </xsl:call-template>
  428. </xsl:otherwise>
  429. </xsl:choose>
  430. </xsl:variable>
  431. <xsl:if test="string-length($n) != 0">
  432. <xsl:element name="meta" namespace="{$opf.namespace}">
  433. <xsl:attribute name="id">
  434. <xsl:value-of select="concat($epub.meta.creator.id, position())"/>
  435. </xsl:attribute>
  436. <xsl:attribute name="property">dcterms:creator</xsl:attribute>
  437. <xsl:value-of select="normalize-space(string($n))"/>
  438. </xsl:element>
  439. <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
  440. <dc:creator>
  441. <xsl:attribute name="id">
  442. <xsl:value-of select="concat($epub.dc.creator.id, position())"/>
  443. </xsl:attribute>
  444. <xsl:value-of select="$n"/>
  445. </dc:creator>
  446. </xsl:if>
  447. </xsl:if>
  448. </xsl:template>
  449. <xsl:template match="editor" mode="opf.metadata">
  450. <xsl:variable name="n">
  451. <xsl:choose>
  452. <xsl:when test="orgname">
  453. <xsl:apply-templates select="orgname"/>
  454. </xsl:when>
  455. <xsl:otherwise>
  456. <xsl:call-template name="person.name">
  457. <xsl:with-param name="node" select="."/>
  458. </xsl:call-template>
  459. </xsl:otherwise>
  460. </xsl:choose>
  461. </xsl:variable>
  462. <xsl:variable name="name">
  463. <xsl:choose>
  464. <xsl:when test="string-length($editor.property) != 0">
  465. <xsl:value-of select="$editor.property"/>
  466. </xsl:when>
  467. <xsl:otherwise>
  468. <xsl:text>contributor</xsl:text>
  469. </xsl:otherwise>
  470. </xsl:choose>
  471. </xsl:variable>
  472. <xsl:element name="meta" namespace="{$opf.namespace}">
  473. <xsl:attribute name="property">
  474. <xsl:text>dcterms:</xsl:text>
  475. <xsl:value-of select="$name"/>
  476. </xsl:attribute>
  477. <xsl:value-of select="normalize-space($n)"/>
  478. </xsl:element>
  479. <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
  480. <xsl:choose>
  481. <xsl:when test="$name = 'creator'">
  482. <dc:creator>
  483. <xsl:value-of select="normalize-space($n)"/>
  484. </dc:creator>
  485. </xsl:when>
  486. <xsl:when test="$name = 'contributor'">
  487. <dc:contributor>
  488. <xsl:value-of select="normalize-space($n)"/>
  489. </dc:contributor>
  490. </xsl:when>
  491. <xsl:otherwise>
  492. <xsl:element namespace="{$dc.namespace}" name="{$name}">
  493. <xsl:value-of select="normalize-space($n)"/>
  494. </xsl:element>
  495. </xsl:otherwise>
  496. </xsl:choose>
  497. </xsl:if>
  498. </xsl:template>
  499. <xsl:template match="corpcredit" mode="opf.metadata">
  500. <xsl:element name="meta" namespace="{$opf.namespace}">
  501. <xsl:attribute name="property">dcterms:contributor</xsl:attribute>
  502. <xsl:value-of select="normalize-space(.)"/>
  503. </xsl:element>
  504. <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
  505. <dc:contributor>
  506. <xsl:value-of select="normalize-space(.)"/>
  507. </dc:contributor>
  508. </xsl:if>
  509. </xsl:template>
  510. <xsl:template match="collab|othercredit" mode="opf.metadata">
  511. <xsl:variable name="content">
  512. <xsl:choose>
  513. <xsl:when test="collabname">
  514. <xsl:apply-templates select="collabname"/>
  515. </xsl:when>
  516. <xsl:when test="org/orgname">
  517. <xsl:apply-templates select="org/orgname"/>
  518. </xsl:when>
  519. <xsl:when test="orgname">
  520. <xsl:apply-templates select="orgname"/>
  521. </xsl:when>
  522. <xsl:when test="personname|firstname|surname|othername">
  523. <xsl:call-template name="person.name"/>
  524. </xsl:when>
  525. <xsl:otherwise>
  526. <xsl:value-of select="."/>
  527. </xsl:otherwise>
  528. </xsl:choose>
  529. </xsl:variable>
  530. <xsl:element name="meta" namespace="{$opf.namespace}">
  531. <xsl:attribute name="property">dcterms:contributor</xsl:attribute>
  532. <xsl:value-of select="normalize-space($content)"/>
  533. </xsl:element>
  534. <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
  535. <dc:contributor>
  536. <xsl:value-of select="normalize-space($content)"/>
  537. </dc:contributor>
  538. </xsl:if>
  539. </xsl:template>
  540. <xsl:template match="date|pubdate" mode="opf.metadata">
  541. <xsl:variable name="date">
  542. <xsl:call-template name="format.meta.date">
  543. <xsl:with-param name="string" select="normalize-space(.)"/>
  544. </xsl:call-template>
  545. </xsl:variable>
  546. <xsl:if test="string-length($date) != 0">
  547. <xsl:element name="meta" namespace="{$opf.namespace}">
  548. <xsl:attribute name="property">dcterms:date</xsl:attribute>
  549. <xsl:value-of select="$date"/>
  550. </xsl:element>
  551. <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
  552. <dc:date>
  553. <xsl:value-of select="$date"/>
  554. </dc:date>
  555. </xsl:if>
  556. </xsl:if>
  557. </xsl:template>
  558. <!-- EPUB3 meta date should be of the form:
  559. YYYY, YYYY-MM or YYYY-MM-DD -->
  560. <xsl:template name="format.meta.date">
  561. <xsl:param name="string" select="''"/>
  562. <xsl:param name="node" select="."/>
  563. <!-- FIXME: this needs further work, so just check the
  564. string format and return the date string for now -->
  565. <xsl:variable name="normalized"
  566. select="translate($string, '0123456789', '##########')"/>
  567. <xsl:variable name="date.ok">
  568. <xsl:choose>
  569. <xsl:when test="string-length($string) = 4 and
  570. $normalized = '####'">1</xsl:when>
  571. <xsl:when test="string-length($string) = 7 and
  572. $normalized = '####-##'">1</xsl:when>
  573. <xsl:when test="string-length($string) = 10 and
  574. $normalized = '####-##-##'">1</xsl:when>
  575. <xsl:when test="string-length($string) = 10 and
  576. $normalized = '####-##-##'">1</xsl:when>
  577. <xsl:otherwise>0</xsl:otherwise>
  578. </xsl:choose>
  579. </xsl:variable>
  580. <xsl:if test="$date.ok = 0">
  581. <xsl:message>
  582. <xsl:text>WARNING: wrong metadata date format: '</xsl:text>
  583. <xsl:value-of select="$string"/>
  584. <xsl:text>' in element </xsl:text>
  585. <xsl:value-of select="local-name($node/..)"/>
  586. <xsl:text>/</xsl:text>
  587. <xsl:value-of select="local-name($node)"/>
  588. <xsl:text>. It must be in one of these forms: </xsl:text>
  589. <xsl:text>YYYY, YYYY-MM, or YYYY-MM-DD.</xsl:text>
  590. </xsl:message>
  591. </xsl:if>
  592. <!-- return the string anyway -->
  593. <xsl:value-of select="$string"/>
  594. </xsl:template>
  595. <!-- Space separate the compontents of the abstract (dropping the inline markup, sadly) -->
  596. <xsl:template match="abstract" mode="opf.metadata">
  597. <xsl:variable name="content">
  598. <xsl:for-each select="formalpara|para|simpara|title">
  599. <xsl:choose>
  600. <xsl:when test="self::formalpara">
  601. <xsl:value-of select="normalize-space(string(title))"/>
  602. <xsl:text>: </xsl:text>
  603. <xsl:value-of select="normalize-space(string(para))"/>
  604. </xsl:when>
  605. <xsl:otherwise>
  606. <xsl:value-of select="normalize-space(string(.))"/>
  607. </xsl:otherwise>
  608. </xsl:choose>
  609. <xsl:if test="self::title">
  610. <xsl:text>:</xsl:text>
  611. </xsl:if>
  612. <xsl:if test="not(position() = last())">
  613. <xsl:text> </xsl:text>
  614. </xsl:if>
  615. </xsl:for-each>
  616. </xsl:variable>
  617. <xsl:element name="meta" namespace="{$opf.namespace}">
  618. <xsl:attribute name="property">dcterms:description</xsl:attribute>
  619. <xsl:copy-of select="$content"/>
  620. </xsl:element>
  621. <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
  622. <dc:description>
  623. <xsl:copy-of select="$content"/>
  624. </dc:description>
  625. </xsl:if>
  626. </xsl:template>
  627. <xsl:template match="subjectset" mode="opf.metadata">
  628. <xsl:apply-templates select="subject/subjectterm" mode="opf.metadata"/>
  629. </xsl:template>
  630. <xsl:template match="subjectterm" mode="opf.metadata">
  631. <xsl:element name="meta" namespace="{$opf.namespace}">
  632. <xsl:attribute name="property">dcterms:subject</xsl:attribute>
  633. <xsl:value-of select="normalize-space(string(.))"/>
  634. </xsl:element>
  635. <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
  636. <dc:subject>
  637. <xsl:value-of select="normalize-space(string(.))"/>
  638. </dc:subject>
  639. </xsl:if>
  640. </xsl:template>
  641. <xsl:template match="keywordset" mode="opf.metadata">
  642. <xsl:apply-templates select="keyword" mode="opf.metadata"/>
  643. </xsl:template>
  644. <xsl:template match="keyword" mode="opf.metadata">
  645. <xsl:element name="meta" namespace="{$opf.namespace}">
  646. <xsl:attribute name="property">dcterms:subject</xsl:attribute>
  647. <xsl:value-of select="normalize-space(string(.))"/>
  648. </xsl:element>
  649. <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
  650. <dc:subject>
  651. <xsl:value-of select="normalize-space(string(.))"/>
  652. </dc:subject>
  653. </xsl:if>
  654. </xsl:template>
  655. <xsl:template match="publisher" mode="opf.metadata">
  656. <xsl:apply-templates select="publishername" mode="opf.metadata"/>
  657. </xsl:template>
  658. <xsl:template match="publishername" mode="opf.metadata">
  659. <xsl:element name="meta" namespace="{$opf.namespace}">
  660. <xsl:attribute name="property">dcterms:publisher</xsl:attribute>
  661. <xsl:value-of select="normalize-space(string(.))"/>
  662. </xsl:element>
  663. <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
  664. <dc:publisher>
  665. <xsl:value-of select="normalize-space(string(.))"/>
  666. </dc:publisher>
  667. </xsl:if>
  668. </xsl:template>
  669. <xsl:template match="bibliocoverage" mode="opf.metadata">
  670. <xsl:element name="meta" namespace="{$opf.namespace}">
  671. <xsl:attribute name="property">dcterms:coverage</xsl:attribute>
  672. <xsl:value-of select="normalize-space(string(.))"/>
  673. </xsl:element>
  674. <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
  675. <dc:coverage>
  676. <xsl:value-of select="normalize-space(string(.))"/>
  677. </dc:coverage>
  678. </xsl:if>
  679. </xsl:template>
  680. <xsl:template match="bibliorelation" mode="opf.metadata">
  681. <xsl:element name="meta" namespace="{$opf.namespace}">
  682. <xsl:attribute name="property">dcterms:relation</xsl:attribute>
  683. <xsl:value-of select="normalize-space(string(.))"/>
  684. </xsl:element>
  685. <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
  686. <dc:relation>
  687. <xsl:value-of select="normalize-space(string(.))"/>
  688. </dc:relation>
  689. </xsl:if>
  690. </xsl:template>
  691. <xsl:template match="bibliosource" mode="opf.metadata">
  692. <xsl:element name="meta" namespace="{$opf.namespace}">
  693. <xsl:attribute name="property">dcterms:source</xsl:attribute>
  694. <xsl:value-of select="normalize-space(string(.))"/>
  695. </xsl:element>
  696. <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
  697. <dc:source>
  698. <xsl:value-of select="normalize-space(string(.))"/>
  699. </dc:source>
  700. </xsl:if>
  701. </xsl:template>
  702. <xsl:template match="copyright" mode="opf.metadata">
  703. <xsl:variable name="copyright.date">
  704. <xsl:call-template name="copyright.years">
  705. <xsl:with-param name="years" select="year"/>
  706. <xsl:with-param name="print.ranges" select="$make.year.ranges"/>
  707. <xsl:with-param name="single.year.ranges" select="$make.single.year.ranges"/>
  708. </xsl:call-template>
  709. </xsl:variable>
  710. <!-- if no docbook date element, use copyright year for single date metadata -->
  711. <xsl:if test="not(../date)">
  712. <xsl:variable name="date.content">
  713. <xsl:call-template name="format.meta.date">
  714. <xsl:with-param name="string">
  715. <xsl:call-template name="copyright.years">
  716. <xsl:with-param name="years" select="year[last()]"/>
  717. <xsl:with-param name="print.ranges" select="0"/>
  718. <xsl:with-param name="single.year.ranges" select="0"/>
  719. </xsl:call-template>
  720. </xsl:with-param>
  721. </xsl:call-template>
  722. </xsl:variable>
  723. <xsl:element name="meta" namespace="{$opf.namespace}">
  724. <xsl:attribute name="property">dcterms:date</xsl:attribute>
  725. <xsl:copy-of select="$date.content"/>
  726. </xsl:element>
  727. <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
  728. <dc:date>
  729. <xsl:copy-of select="$date.content"/>
  730. </dc:date>
  731. </xsl:if>
  732. </xsl:if>
  733. <xsl:variable name="rights.content">
  734. <xsl:call-template name="gentext">
  735. <xsl:with-param name="key" select="'Copyright'"/>
  736. </xsl:call-template>
  737. <xsl:call-template name="gentext.space"/>
  738. <xsl:text>&#x00A9;</xsl:text>
  739. <xsl:call-template name="gentext.space"/>
  740. <xsl:value-of select="$copyright.date"/>
  741. <xsl:call-template name="gentext.space"/>
  742. <xsl:apply-templates select="holder" mode="titlepage.mode"/>
  743. </xsl:variable>
  744. <xsl:element name="meta" namespace="{$opf.namespace}">
  745. <xsl:attribute name="property">dcterms:rights</xsl:attribute>
  746. <xsl:copy-of select="$rights.content"/>
  747. </xsl:element>
  748. <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
  749. <dc:rights>
  750. <xsl:copy-of select="$rights.content"/>
  751. </dc:rights>
  752. </xsl:if>
  753. <xsl:element name="meta" namespace="{$opf.namespace}">
  754. <xsl:attribute name="property">dcterms:rightsHolder</xsl:attribute>
  755. <xsl:apply-templates select="holder" mode="titlepage.mode"/>
  756. </xsl:element>
  757. </xsl:template>
  758. <xsl:template name="package.guide">
  759. <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
  760. <xsl:variable name="toc.params">
  761. <xsl:call-template name="find.path.params">
  762. <xsl:with-param name="node" select="."/>
  763. <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
  764. </xsl:call-template>
  765. </xsl:variable>
  766. <xsl:if test="contains($toc.params, 'toc') or
  767. $info/cover or
  768. $info//mediaobject[@role='cover' or ancestor::cover]">
  769. <xsl:element namespace="{$opf.namespace}" name="guide">
  770. <xsl:if test="$info/cover or
  771. $info//mediaobject[@role='cover' or ancestor::cover]">
  772. <xsl:element namespace="{$opf.namespace}" name="reference">
  773. <xsl:attribute name="href">
  774. <xsl:value-of select="$epub.cover.filename" />
  775. </xsl:attribute>
  776. <xsl:attribute name="type">cover</xsl:attribute>
  777. <xsl:attribute name="title">Cover</xsl:attribute>
  778. </xsl:element>
  779. </xsl:if>
  780. <xsl:if test="contains($toc.params, 'toc')">
  781. <xsl:element namespace="{$opf.namespace}" name="reference">
  782. <xsl:attribute name="href">
  783. <xsl:call-template name="toc-href">
  784. <xsl:with-param name="node" select="."/>
  785. </xsl:call-template>
  786. </xsl:attribute>
  787. <xsl:attribute name="type">toc</xsl:attribute>
  788. <xsl:attribute name="title">Table of Contents</xsl:attribute>
  789. </xsl:element>
  790. </xsl:if>
  791. </xsl:element>
  792. </xsl:if>
  793. </xsl:template>
  794. <xsl:template name="package-identifier">
  795. <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
  796. <xsl:choose>
  797. <xsl:when test="$info/biblioid">
  798. <xsl:if test="$info/biblioid[1][@class = 'doi' or
  799. @class = 'isbn' or
  800. @class = 'isrn' or
  801. @class = 'istc' or
  802. @class = 'issn']">
  803. <xsl:text>urn:</xsl:text>
  804. <xsl:value-of select="$info/biblioid[1]/@class"/>
  805. <xsl:text>:</xsl:text>
  806. </xsl:if>
  807. <xsl:value-of select="normalize-space($info/biblioid[1])"/>
  808. </xsl:when>
  809. <xsl:when test="$info/isbn">
  810. <xsl:text>urn:isbn:</xsl:text>
  811. <xsl:value-of select="$info/isbn[1]"/>
  812. </xsl:when>
  813. <xsl:when test="$info/issn">
  814. <xsl:text>urn:issn:</xsl:text>
  815. <xsl:value-of select="$info/issn[1]"/>
  816. </xsl:when>
  817. <xsl:otherwise>
  818. <xsl:choose>
  819. <xsl:when test="$info/invpartnumber">
  820. <xsl:value-of select="$info/invpartnumber[1]"/>
  821. </xsl:when>
  822. <xsl:when test="$info/issuenum">
  823. <xsl:value-of select="$info/issuenum[1]"/>
  824. </xsl:when>
  825. <xsl:when test="$info/productnumber">
  826. <xsl:value-of select="$info/productnumber[1]"/>
  827. </xsl:when>
  828. <xsl:when test="$info/seriesvolnums">
  829. <xsl:value-of select="$info/seriesvolnums[1]"/>
  830. </xsl:when>
  831. <xsl:when test="$info/volumenum">
  832. <xsl:value-of select="$info/volumenum[1]"/>
  833. </xsl:when>
  834. <!-- Deprecated -->
  835. <xsl:when test="$info/pubsnumber">
  836. <xsl:value-of select="$info/pubsnumber[1]"/>
  837. </xsl:when>
  838. </xsl:choose>
  839. <xsl:text>_</xsl:text>
  840. <xsl:choose>
  841. <xsl:when test="@id">
  842. <xsl:value-of select="@id"/>
  843. </xsl:when>
  844. <xsl:when test="@xml:id">
  845. <xsl:value-of select="@xml:id"/>
  846. </xsl:when>
  847. <xsl:otherwise>
  848. <!-- TODO: Do UUIDs here -->
  849. <xsl:value-of select="generate-id(.)"/>
  850. </xsl:otherwise>
  851. </xsl:choose>
  852. </xsl:otherwise>
  853. </xsl:choose>
  854. </xsl:template>
  855. <!-- EPUB3: add epub:type attribute where appropriate -->
  856. <xsl:template match="*" mode="common.html.attributes">
  857. <xsl:param name="class" select="local-name(.)"/>
  858. <xsl:param name="inherit" select="0"/>
  859. <xsl:call-template name="generate.html.lang"/>
  860. <xsl:call-template name="dir">
  861. <xsl:with-param name="inherit" select="$inherit"/>
  862. </xsl:call-template>
  863. <xsl:apply-templates select="." mode="class.attribute">
  864. <xsl:with-param name="class" select="$class"/>
  865. </xsl:apply-templates>
  866. <xsl:call-template name="generate.html.title"/>
  867. <xsl:apply-templates select="." mode="epub.type"/>
  868. </xsl:template>
  869. <xsl:template match="*" mode="epub.type" priority="-1"/>
  870. <xsl:template match="chapter
  871. |appendix
  872. |epigraph
  873. |warning
  874. |preface
  875. |index
  876. |colophon
  877. |glossary
  878. |biblioentry
  879. |bibliography
  880. |dedication
  881. |sidebar
  882. |footnote
  883. |glossterm
  884. |glossdef
  885. |bridgehead
  886. |part" mode="epub.type">
  887. <xsl:variable name="type" select="local-name()"/>
  888. <xsl:if test="$epub.output.epub.types != 0">
  889. <xsl:attribute name="epub:type">
  890. <xsl:value-of select="$type"/>
  891. </xsl:attribute>
  892. </xsl:if>
  893. </xsl:template>
  894. <xsl:template match="section[parent::chapter] | sect1" mode="epub.type">
  895. <xsl:if test="$epub.output.epub.types != 0">
  896. <xsl:attribute name="epub:type">subchapter</xsl:attribute>
  897. </xsl:if>
  898. </xsl:template>
  899. <xsl:template match="section[not(parent::chapter)] |
  900. sect2 |
  901. sect3 |
  902. sect4 |
  903. sect5 |
  904. sect6" mode="epub.type">
  905. <xsl:if test="$epub.output.epub.types != 0">
  906. <xsl:attribute name="epub:type">division</xsl:attribute>
  907. </xsl:if>
  908. </xsl:template>
  909. <xsl:template match="note|tip|caution|important" mode="epub.type">
  910. <xsl:if test="$epub.output.epub.types != 0">
  911. <xsl:attribute name="epub:type">notice</xsl:attribute>
  912. </xsl:if>
  913. </xsl:template>
  914. <xsl:template match="orderedlist|itemizedlist|variablelist|simplelist" mode="epub.type">
  915. <xsl:if test="$epub.output.epub.types != 0">
  916. <xsl:attribute name="epub:type">list</xsl:attribute>
  917. </xsl:if>
  918. </xsl:template>
  919. <xsl:template match="listitem" mode="epub.type">
  920. <xsl:if test="$epub.output.epub.types != 0">
  921. <xsl:attribute name="epub:type">list-item</xsl:attribute>
  922. </xsl:if>
  923. </xsl:template>
  924. <!-- EPUB3: to add attributes to root output element -->
  925. <xsl:template name="root.attributes">
  926. <!-- collect and output all namespace declarations -->
  927. <xsl:call-template name="all.namespaces"/>
  928. </xsl:template>
  929. <xsl:template name="all.namespaces">
  930. <!-- add the epub3 namespaces to the top output element -->
  931. <xsl:variable name="temp">
  932. <epub:foo/>
  933. <m:foo/>
  934. <pls:foo/>
  935. <ssml:foo/>
  936. <svg:foo/>
  937. </xsl:variable>
  938. <xsl:variable name="nodes" select="exsl:node-set($temp)"/>
  939. <xsl:for-each select="$nodes//*/namespace::*">
  940. <xsl:copy-of select="."/>
  941. </xsl:for-each>
  942. </xsl:template>
  943. <xsl:template name="add.package.namespaces">
  944. <!-- add the epub3 package namespaces to the top output element -->
  945. <xsl:variable name="temp">
  946. <dc:foo/>
  947. <dcterms:foo/>
  948. </xsl:variable>
  949. <xsl:variable name="nodes" select="exsl:node-set($temp)"/>
  950. <xsl:for-each select="$nodes//*[local-name(.) ='foo']/namespace::*">
  951. <xsl:if test="contains(., 'purl.org')">
  952. <xsl:copy-of select="."/>
  953. </xsl:if>
  954. </xsl:for-each>
  955. </xsl:template>
  956. <xsl:template name="footnotes.attributes">
  957. <xsl:if test="$epub.output.epub.types != 0">
  958. <xsl:attribute name="epub:type">footnotes</xsl:attribute>
  959. </xsl:if>
  960. </xsl:template>
  961. <xsl:template name="package.manifest">
  962. <xsl:element name="manifest" namespace="{$opf.namespace}">
  963. <xsl:if test="$epub.include.ncx != 0">
  964. <xsl:call-template name="manifest.ncx"/>
  965. </xsl:if>
  966. <xsl:call-template name="manifest.fonts"/>
  967. <xsl:call-template name="manifest.toc"/>
  968. <xsl:call-template name="manifest.css"/>
  969. <xsl:call-template name="manifest.cover"/>
  970. <xsl:call-template name="manifest.other.items"/>
  971. <xsl:call-template name="manifest.content.items"/>
  972. <xsl:call-template name="user.manifest.items"/>
  973. </xsl:element>
  974. </xsl:template>
  975. <xsl:template name="user.manifest.items"/>
  976. <xsl:template name="manifest.css">
  977. <xsl:if test="$html.stylesheet != ''">
  978. <xsl:call-template name="css.item">
  979. <xsl:with-param name="stylesheets" select="$html.stylesheet"/>
  980. </xsl:call-template>
  981. </xsl:if>
  982. <xsl:if test="string-length($docbook.css.source) != 0">
  983. <xsl:variable name="dfilename">
  984. <xsl:call-template name="css.output.filename">
  985. <xsl:with-param name="src" select="$docbook.css.source"/>
  986. </xsl:call-template>
  987. </xsl:variable>
  988. <xsl:element namespace="{$opf.namespace}" name="item">
  989. <xsl:attribute name="media-type">text/css</xsl:attribute>
  990. <xsl:attribute name="id">docbook-css</xsl:attribute>
  991. <xsl:attribute name="href">
  992. <xsl:value-of select="$dfilename"/>
  993. </xsl:attribute>
  994. </xsl:element>
  995. </xsl:if>
  996. <xsl:if test="string-length($custom.css.source) != 0">
  997. <xsl:variable name="cfilename">
  998. <xsl:call-template name="css.output.filename">
  999. <xsl:with-param name="src" select="$custom.css.source"/>
  1000. </xsl:call-template>
  1001. </xsl:variable>
  1002. <xsl:element namespace="{$opf.namespace}" name="item">
  1003. <xsl:attribute name="media-type">text/css</xsl:attribute>
  1004. <xsl:attribute name="id">custom-css</xsl:attribute>
  1005. <xsl:attribute name="href">
  1006. <xsl:value-of select="$cfilename"/>
  1007. </xsl:attribute>
  1008. </xsl:element>
  1009. </xsl:if>
  1010. </xsl:template>
  1011. <xsl:template name="css.item">
  1012. <xsl:param name="stylesheets" select="''"/>
  1013. <xsl:param name="count" select="1"/>
  1014. <xsl:choose>
  1015. <xsl:when test="contains($stylesheets, ' ')">
  1016. <xsl:variable name="css.filename" select="substring-before($stylesheets, ' ')"/>
  1017. <xsl:if test="$css.filename != ''">
  1018. <xsl:element namespace="{$opf.namespace}" name="item">
  1019. <xsl:attribute name="media-type">text/css</xsl:attribute>
  1020. <xsl:attribute name="id">
  1021. <xsl:text>html-css</xsl:text>
  1022. <xsl:if test="$count &gt; 1">
  1023. <xsl:value-of select="$count"/>
  1024. </xsl:if>
  1025. </xsl:attribute>
  1026. <xsl:attribute name="href">
  1027. <xsl:value-of select="$css.filename"/>
  1028. </xsl:attribute>
  1029. </xsl:element>
  1030. </xsl:if>
  1031. <xsl:call-template name="css.item">
  1032. <xsl:with-param name="stylesheets" select="substring-after($stylesheets, ' ')"/>
  1033. <xsl:with-param name="count" select="$count + 1"/>
  1034. </xsl:call-template>
  1035. </xsl:when>
  1036. <xsl:otherwise>
  1037. <xsl:if test="$stylesheets != ''">
  1038. <xsl:element namespace="{$opf.namespace}" name="item">
  1039. <xsl:attribute name="media-type">text/css</xsl:attribute>
  1040. <xsl:attribute name="id">
  1041. <xsl:text>html-css</xsl:text>
  1042. <xsl:if test="$count &gt; 1">
  1043. <xsl:value-of select="$count"/>
  1044. </xsl:if>
  1045. </xsl:attribute>
  1046. <xsl:attribute name="href">
  1047. <xsl:value-of select="$stylesheets"/>
  1048. </xsl:attribute>
  1049. </xsl:element>
  1050. </xsl:if>
  1051. </xsl:otherwise>
  1052. </xsl:choose>
  1053. </xsl:template>
  1054. <xsl:template name="manifest.ncx">
  1055. <xsl:element name="item" namespace="{$opf.namespace}">
  1056. <xsl:attribute name="id">
  1057. <xsl:value-of select="$epub.ncx.manifest.id"/>
  1058. </xsl:attribute>
  1059. <xsl:attribute name="href">
  1060. <xsl:value-of select="$epub.ncx.filename"/>
  1061. </xsl:attribute>
  1062. <xsl:attribute name="media-type">
  1063. <xsl:value-of select="$epub.ncx.mediatype"/>
  1064. </xsl:attribute>
  1065. </xsl:element>
  1066. </xsl:template>
  1067. <xsl:template name="manifest.fonts"/>
  1068. <!--Misc items in the manifest based on content -->
  1069. <xsl:template name="manifest.other.items">
  1070. </xsl:template>
  1071. <xsl:template name="manifest.cover">
  1072. <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
  1073. <xsl:variable name="cover.image"
  1074. select="$info//mediaobject[@role='cover' or ancestor::cover]"/>
  1075. <xsl:if test="$cover.image">
  1076. <!-- generate the manifest link to that page -->
  1077. <xsl:variable name="olist" select="$cover.image/imageobject|$cover.image/imageobjectco
  1078. |$cover.image/videoobject|$cover.image/audioobject
  1079. |$cover.image/textobject"/>
  1080. <xsl:variable name="object.index">
  1081. <xsl:call-template name="select.mediaobject.index">
  1082. <xsl:with-param name="olist" select="$olist"/>
  1083. <xsl:with-param name="count" select="1"/>
  1084. </xsl:call-template>
  1085. </xsl:variable>
  1086. <xsl:variable name="object" select="$olist[position() = $object.index]"/>
  1087. <xsl:variable name="output_filename">
  1088. <xsl:call-template name="mediaobject.filename">
  1089. <xsl:with-param name="object" select="$object"/>
  1090. </xsl:call-template>
  1091. </xsl:variable>
  1092. <xsl:variable name="image.filename">
  1093. <xsl:if test="$img.src.path != '' and
  1094. not(starts-with($output_filename, '/')) and
  1095. not(contains($output_filename, '://'))">
  1096. <xsl:value-of select="$img.src.path"/>
  1097. </xsl:if>
  1098. <xsl:value-of select="$output_filename"/>
  1099. </xsl:variable>
  1100. <xsl:variable name="image.extension">
  1101. <xsl:call-template name="filename-extension">
  1102. <xsl:with-param name="filename" select="$image.filename"/>
  1103. </xsl:call-template>
  1104. </xsl:variable>
  1105. <xsl:variable name="image.type">
  1106. <xsl:call-template name="graphic.format.content-type">
  1107. <xsl:with-param name="format" select="translate($image.extension,
  1108. &lowercase;, &uppercase;)"/>
  1109. </xsl:call-template>
  1110. </xsl:variable>
  1111. <!-- Reference to cover html file -->
  1112. <xsl:element namespace="{$opf.namespace}" name="item">
  1113. <xsl:attribute name="id">
  1114. <xsl:value-of select="$epub.cover.filename.id"/>
  1115. </xsl:attribute>
  1116. <xsl:attribute name="href">
  1117. <xsl:value-of select="$epub.cover.filename"/>
  1118. </xsl:attribute>
  1119. <xsl:attribute name="media-type">
  1120. <xsl:value-of select="$epub.xhtml.mediatype"/>
  1121. </xsl:attribute>
  1122. </xsl:element>
  1123. <!-- special item with property="cover-image" -->
  1124. <xsl:element namespace="{$opf.namespace}" name="item">
  1125. <xsl:attribute name="id">
  1126. <xsl:value-of select="$epub.cover.image.id"/>
  1127. </xsl:attribute>
  1128. <xsl:attribute name="properties">cover-image</xsl:attribute>
  1129. <xsl:attribute name="href">
  1130. <xsl:value-of select="$image.filename"/>
  1131. </xsl:attribute>
  1132. <xsl:if test="$image.type">
  1133. <xsl:attribute name="media-type">
  1134. <xsl:value-of select="$image.type"/>
  1135. </xsl:attribute>
  1136. </xsl:if>
  1137. </xsl:element>
  1138. <!-- And generate the cover html file -->
  1139. <xsl:apply-templates select="$cover.image"/>
  1140. </xsl:if>
  1141. </xsl:template>
  1142. <xsl:template name="manifest.toc">
  1143. <xsl:variable name="toc.params">
  1144. <xsl:call-template name="find.path.params">
  1145. <xsl:with-param name="node" select="."/>
  1146. <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
  1147. </xsl:call-template>
  1148. </xsl:variable>
  1149. <xsl:if test="contains($toc.params, 'toc')">
  1150. <xsl:element namespace="{$opf.namespace}" name="item">
  1151. <xsl:attribute name="id">
  1152. <xsl:value-of select="$epub.html.toc.id"/>
  1153. </xsl:attribute>
  1154. <xsl:attribute name="properties">nav</xsl:attribute>
  1155. <xsl:attribute name="media-type">
  1156. <xsl:value-of select="$epub.xhtml.mediatype"/>
  1157. </xsl:attribute>
  1158. <xsl:attribute name="href">
  1159. <xsl:call-template name="toc-href">
  1160. <xsl:with-param name="node" select="."/>
  1161. </xsl:call-template>
  1162. </xsl:attribute>
  1163. </xsl:element>
  1164. </xsl:if>
  1165. </xsl:template>
  1166. <xsl:template name="toc-href">
  1167. <xsl:param name="node" select="."/>
  1168. <!-- FIXME -->
  1169. <xsl:apply-templates select="$node" mode="recursive-chunk-filename">
  1170. <xsl:with-param name="recursive" select="true()"/>
  1171. </xsl:apply-templates>
  1172. <xsl:text>-toc</xsl:text>
  1173. <xsl:value-of select="$html.ext"/>
  1174. </xsl:template>
  1175. <xsl:template match="*" mode="recursive-chunk-filename">
  1176. <!-- placeholder for real template in chunking stylesheet -->
  1177. <xsl:value-of select="concat(local-name(.), '-', generate-id(.))"/>
  1178. </xsl:template>
  1179. <xsl:template name="manifest.content.items">
  1180. <xsl:apply-templates select="." mode="package.manifest"/>
  1181. <xsl:call-template name="manifest.images"/>
  1182. </xsl:template>
  1183. <xsl:template match="text()" mode="package.manifest"/>
  1184. <xsl:template match="mediaobject|mediaobjectco|inlinemediaobject" priority="1"
  1185. mode="package.manifest">
  1186. <!-- These are handled out of line so a unique list is created
  1187. to remove duplicate references -->
  1188. </xsl:template>
  1189. <xsl:template match="*" mode="package.manifest">
  1190. <xsl:variable name="is.chunk">
  1191. <xsl:call-template name="chunk">
  1192. <xsl:with-param name="node" select="."/>
  1193. </xsl:call-template>
  1194. </xsl:variable>
  1195. <xsl:if test="$is.chunk != 0">
  1196. <xsl:variable name="href">
  1197. <xsl:call-template name="href.target.with.base.dir">
  1198. <xsl:with-param name="context" select="/"/>
  1199. </xsl:call-template>
  1200. </xsl:variable>
  1201. <xsl:variable name="id" select="concat($epub.package.id.prefix, generate-id())"/>
  1202. <xsl:variable name="properties.set">
  1203. <xsl:call-template name="svg.property"/>
  1204. <xsl:text> </xsl:text>
  1205. <xsl:call-template name="mathml.property"/>
  1206. </xsl:variable>
  1207. <xsl:variable name="properties" select="normalize-space($properties.set)"/>
  1208. <xsl:element namespace="{$opf.namespace}" name="item">
  1209. <xsl:attribute name="id">
  1210. <xsl:value-of select="$id"/>
  1211. </xsl:attribute>
  1212. <xsl:attribute name="href">
  1213. <xsl:value-of select="$href"/>
  1214. </xsl:attribute>
  1215. <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
  1216. <xsl:if test="string-length($properties) != 0">
  1217. <xsl:attribute name="properties">
  1218. <xsl:value-of select="$properties"/>
  1219. </xsl:attribute>
  1220. </xsl:if>
  1221. </xsl:element>
  1222. </xsl:if>
  1223. <xsl:apply-templates mode="package.manifest"/>
  1224. </xsl:template>
  1225. <xsl:template name="svg.property">
  1226. <xsl:param name="this.chunk" select="."/>
  1227. <xsl:variable name="genid" select="generate-id($this.chunk)"/>
  1228. <!-- get the chunkfast div element for this chunk -->
  1229. <xsl:variable name="div" select="$chunkset[@id=$genid or @xml:id=$genid]"/>
  1230. <!-- get the chunkfast div element the next chunk -->
  1231. <xsl:variable name="nextdiv"
  1232. select="($div/following-sibling::cf:div|
  1233. $div/following::cf:div|
  1234. $div/cf:div)[1]"/>
  1235. <!-- get the element corresponding to the next chunk -->
  1236. <xsl:variable name="next.chunk" select="key('genid', ($nextdiv/@id|$nextdiv/@xml:id)[1])"/>
  1237. <xsl:choose>
  1238. <xsl:when test="$next.chunk">
  1239. <xsl:variable name="this.imagedata"
  1240. select="$this.chunk//mediaobject"/>
  1241. <xsl:variable name="before.next"
  1242. select="$next.chunk/preceding::mediaobject"/>
  1243. <!-- select for an SVG imagedata in the intersection of them -->
  1244. <xsl:variable name="mediaobject.set"
  1245. select="$this.imagedata[count(.|$before.next) = count($before.next)]"/>
  1246. <xsl:variable name="svg.imagedata">
  1247. <xsl:for-each select="$mediaobject.set">
  1248. <xsl:variable name="olist" select="imageobject[not(@role = 'poster')] |
  1249. imageobjectco"/>
  1250. <xsl:variable name="mediaobject.index">
  1251. <xsl:call-template name="select.mediaobject.index">
  1252. <xsl:with-param name="olist" select="$olist"/>
  1253. </xsl:call-template>
  1254. </xsl:variable>
  1255. <xsl:variable name="object" select="$olist[position() = $mediaobject.index]"/>
  1256. <xsl:if test="$object/imagedata[contains(
  1257. substring(@fileref, string-length(@fileref)-3,4), '.svg')]">
  1258. <xsl:text>svg</xsl:text>
  1259. </xsl:if>
  1260. </xsl:for-each>
  1261. </xsl:variable>
  1262. <xsl:if test="contains($svg.imagedata, 'svg')">
  1263. <xsl:text>svg</xsl:text>
  1264. </xsl:if>
  1265. </xsl:when>
  1266. <xsl:otherwise>
  1267. <xsl:variable name="mediaobject.set"
  1268. select="$this.chunk//mediaobject"/>
  1269. <xsl:variable name="svg.imagedata">
  1270. <xsl:for-each select="$mediaobject.set">
  1271. <xsl:variable name="olist" select="imageobject[not(@role = 'poster')] |
  1272. imageobjectco"/>
  1273. <xsl:variable name="mediaobject.index">
  1274. <xsl:call-template name="select.mediaobject.index">
  1275. <xsl:with-param name="olist" select="$olist"/>
  1276. </xsl:call-template>
  1277. </xsl:variable>
  1278. <xsl:variable name="object" select="$olist[position() = $mediaobject.index]"/>
  1279. <xsl:if test="$object/imagedata[contains(
  1280. substring(@fileref, string-length(@fileref)-3,4), '.svg')]">
  1281. <xsl:text>svg</xsl:text>
  1282. </xsl:if>
  1283. </xsl:for-each>
  1284. </xsl:variable>
  1285. <xsl:if test="contains($svg.imagedata, 'svg')">
  1286. <xsl:text>svg</xsl:text>
  1287. </xsl:if>
  1288. </xsl:otherwise>
  1289. </xsl:choose>
  1290. </xsl:template>
  1291. <xsl:template name="mathml.property">
  1292. <xsl:param name="this.chunk" select="."/>
  1293. <xsl:variable name="genid" select="generate-id($this.chunk)"/>
  1294. <!-- get the chunkfast div element for this chunk -->
  1295. <xsl:variable name="div" select="$chunkset[@id=$genid or @xml:id=$genid]"/>
  1296. <!-- get the chunkfast div element the next chunk -->
  1297. <xsl:variable name="nextdiv"
  1298. select="($div/following-sibling::cf:div|
  1299. $div/following::cf:div|
  1300. $div/cf:div)[1]"/>
  1301. <!-- get the element corresponding to the next chunk -->
  1302. <xsl:variable name="next.chunk" select="key('genid', ($nextdiv/@id|$nextdiv/@xml:id)[1])"/>
  1303. <xsl:variable name="this.math"
  1304. select="$this.chunk//m:*"/>
  1305. <xsl:variable name="before.next"
  1306. select="$next.chunk/preceding::m:*"/>
  1307. <!-- select for an SVG imagedata in the intersection of them -->
  1308. <xsl:variable name="intersection"
  1309. select="$this.math[count(.|$before.next) = count($before.next)]"/>
  1310. <xsl:if test="count($intersection) != 0">
  1311. <xsl:text>mathml</xsl:text>
  1312. </xsl:if>
  1313. </xsl:template>
  1314. <xsl:template name="manifest.image.item">
  1315. </xsl:template>
  1316. <!-- Need a uniqued list of images -->
  1317. <xsl:template name="manifest.images">
  1318. <xsl:message>Generating image list ...</xsl:message>
  1319. <xsl:variable name="imagelist">
  1320. <xsl:choose>
  1321. <xsl:when test="$rootid != ''">
  1322. <xsl:apply-templates select="key('id', $rootid)" mode="enumerate-images"/>
  1323. </xsl:when>
  1324. <xsl:otherwise>
  1325. <xsl:apply-templates select="/" mode="enumerate-images"/>
  1326. </xsl:otherwise>
  1327. </xsl:choose>
  1328. </xsl:variable>
  1329. <xsl:choose>
  1330. <xsl:when test="$exsl.node.set.available != 0 and
  1331. function-available('set:distinct')">
  1332. <xsl:for-each select="set:distinct(exsl:node-set($imagelist)/*)">
  1333. <xsl:if test="string-length(tmp-href) != 0">
  1334. <!-- convert the child elements to attributes -->
  1335. <xsl:element name="item" namespace="{$opf.namespace}">
  1336. <xsl:attribute name="id">
  1337. <xsl:value-of select="generate-id()"/>
  1338. </xsl:attribute>
  1339. <xsl:attribute name="href">
  1340. <xsl:value-of select="tmp-href"/>
  1341. </xsl:attribute>
  1342. <xsl:attribute name="media-type">
  1343. <xsl:value-of select="media-type"/>
  1344. </xsl:attribute>
  1345. </xsl:element>
  1346. </xsl:if>
  1347. </xsl:for-each>
  1348. </xsl:when>
  1349. <xsl:when test="$exsl.node.set.available != 0">
  1350. <xsl:for-each select="exsl:node-set($imagelist)/*">
  1351. <xsl:element name="item" namespace="{$opf.namespace}">
  1352. <xsl:attribute name="id">
  1353. <xsl:value-of select="generate-id()"/>
  1354. </xsl:attribute>
  1355. <xsl:attribute name="href">
  1356. <xsl:value-of select="tmp-href"/>
  1357. </xsl:attribute>
  1358. <xsl:attribute name="media-type">
  1359. <xsl:value-of select="media-type"/>
  1360. </xsl:attribute>
  1361. </xsl:element>
  1362. </xsl:for-each>
  1363. </xsl:when>
  1364. <xsl:otherwise>
  1365. <xsl:message terminate="yes">
  1366. <xsl:text>ERROR: cannot process images list without </xsl:text>
  1367. <xsl:text>exsl:node-set() function</xsl:text>
  1368. </xsl:message>
  1369. <!-- cannot do this without node-set() -->
  1370. </xsl:otherwise>
  1371. </xsl:choose>
  1372. </xsl:template>
  1373. <xsl:template match="*" mode="enumerate-images">
  1374. <xsl:apply-templates mode="enumerate-images"/>
  1375. </xsl:template>
  1376. <xsl:template match="text()" mode="enumerate-images"/>
  1377. <xsl:template match="graphic|inlinegraphic[@format!='linespecific']"
  1378. mode="enumerate-images">
  1379. </xsl:template>
  1380. <!-- cover image handled separates to give it an extra property attribute -->
  1381. <xsl:template match="mediaobject[@role='cover' or ancestor::cover]"
  1382. mode="enumerate-images"/>
  1383. <xsl:template match="mediaobject|inlinemediaobject" mode="enumerate-images">
  1384. <xsl:variable name="olist"
  1385. select="imageobject[not(@role = 'poster')]
  1386. |imageobjectco
  1387. |videoobject
  1388. |audioobject
  1389. |textobject"/>
  1390. <xsl:variable name="object.index">
  1391. <xsl:call-template name="select.mediaobject.index">
  1392. <xsl:with-param name="olist" select="$olist"/>
  1393. <xsl:with-param name="count" select="1"/>
  1394. </xsl:call-template>
  1395. </xsl:variable>
  1396. <xsl:variable name="object" select="$olist[position() = $object.index]"/>
  1397. <xsl:apply-templates select="$object" mode="enumerate-images"/>
  1398. <!-- also include a poster image if present -->
  1399. <xsl:apply-templates select="imageobject[@role = 'poster']" mode="enumerate-images"/>
  1400. </xsl:template>
  1401. <xsl:template match="imageobject|videoobject|audioobject" mode="enumerate-images">
  1402. <xsl:param name="object" select="."/>
  1403. <xsl:if test="$object">
  1404. <xsl:variable name="output_filename">
  1405. <xsl:call-template name="mediaobject.filename">
  1406. <xsl:with-param name="object" select="$object"/>
  1407. </xsl:call-template>
  1408. </xsl:variable>
  1409. <xsl:variable name="image.filename">
  1410. <xsl:if test="$img.src.path != '' and
  1411. not(starts-with($output_filename, '/')) and
  1412. not(contains($output_filename, '://'))">
  1413. <xsl:value-of select="$img.src.path"/>
  1414. </xsl:if>
  1415. <xsl:value-of select="$output_filename"/>
  1416. </xsl:variable>
  1417. <xsl:variable name="image.extension">
  1418. <xsl:call-template name="filename-extension">
  1419. <xsl:with-param name="filename" select="$image.filename"/>
  1420. </xsl:call-template>
  1421. </xsl:variable>
  1422. <xsl:variable name="image.type">
  1423. <xsl:call-template name="graphic.format.content-type">
  1424. <xsl:with-param name="format" select="translate($image.extension,
  1425. &lowercase;, &uppercase;)"/>
  1426. </xsl:call-template>
  1427. </xsl:variable>
  1428. <xsl:element name="tmp-filename" namespace="">
  1429. <xsl:element name="tmp-href" namespace="">
  1430. <xsl:value-of select="$image.filename"/>
  1431. </xsl:element>
  1432. <xsl:element name="media-type" namespace="">
  1433. <xsl:value-of select="$image.type"/>
  1434. </xsl:element>
  1435. </xsl:element>
  1436. </xsl:if>
  1437. </xsl:template>
  1438. <!-- Add in the generated images -->
  1439. <xsl:template match="note|caution|warning|important|tip" mode="enumerate-images">
  1440. <xsl:if test="$admon.graphics != 0">
  1441. <xsl:variable name="image.filename">
  1442. <xsl:call-template name="admon.graphic"/>
  1443. </xsl:variable>
  1444. <xsl:variable name="image.type">
  1445. <xsl:call-template name="graphic.format.content-type">
  1446. <xsl:with-param name="format" select="translate(
  1447. substring-after($admon.graphics.extension,'.'),
  1448. &lowercase;, &uppercase;)"/>
  1449. </xsl:call-template>
  1450. </xsl:variable>
  1451. <xsl:element name="tmp-filename" namespace="">
  1452. <xsl:element name="tmp-href" namespace="">
  1453. <xsl:value-of select="$image.filename"/>
  1454. </xsl:element>
  1455. <xsl:element name="media-type" namespace="">
  1456. <xsl:value-of select="$image.type"/>
  1457. </xsl:element>
  1458. </xsl:element>
  1459. </xsl:if>
  1460. </xsl:template>
  1461. <xsl:template match="callout" mode="enumerate-images">
  1462. <!-- process arearefs to get name of callout bug image files -->
  1463. <xsl:if test="$callout.graphics != 0">
  1464. <xsl:variable name="arearefs">
  1465. <xsl:call-template name="callout.arearefs">
  1466. <xsl:with-param name="arearefs" select="@arearefs"/>
  1467. </xsl:call-template>
  1468. </xsl:variable>
  1469. <xsl:variable name="nodes" select="exsl:node-set($arearefs)"/>
  1470. <xsl:for-each select="$nodes//*[@src]">
  1471. <xsl:variable name="image.filename" select="@src"/>
  1472. <xsl:variable name="image.type">
  1473. <xsl:call-template name="graphic.format.content-type">
  1474. <xsl:with-param name="format" select="translate(
  1475. substring-after($callout.graphics.extension,'.'),
  1476. &lowercase;, &uppercase;)"/>
  1477. </xsl:call-template>
  1478. </xsl:variable>
  1479. <xsl:element name="tmp-filename" namespace="">
  1480. <xsl:element name="tmp-href" namespace="">
  1481. <xsl:value-of select="$image.filename"/>
  1482. </xsl:element>
  1483. <xsl:element name="media-type" namespace="">
  1484. <xsl:value-of select="$image.type"/>
  1485. </xsl:element>
  1486. </xsl:element>
  1487. </xsl:for-each>
  1488. </xsl:if>
  1489. </xsl:template>
  1490. <xsl:template match="co" mode="enumerate-images">
  1491. <!-- process co to get name of callout bug image file -->
  1492. <xsl:if test="$callout.graphics != 0">
  1493. <xsl:variable name="result">
  1494. <xsl:apply-templates select="." mode="callout-bug"/>
  1495. </xsl:variable>
  1496. <xsl:variable name="nodes" select="exsl:node-set($result)"/>
  1497. <xsl:for-each select="$nodes//*[@src]">
  1498. <xsl:variable name="image.filename" select="@src"/>
  1499. <xsl:variable name="image.type">
  1500. <xsl:call-template name="graphic.format.content-type">
  1501. <xsl:with-param name="format" select="translate(
  1502. substring-after($callout.graphics.extension,'.'),
  1503. &lowercase;, &uppercase;)"/>
  1504. </xsl:call-template>
  1505. </xsl:variable>
  1506. <xsl:element name="tmp-filename" namespace="">
  1507. <xsl:element name="tmp-href" namespace="">
  1508. <xsl:value-of select="$image.filename"/>
  1509. </xsl:element>
  1510. <xsl:element name="media-type" namespace="">
  1511. <xsl:value-of select="$image.type"/>
  1512. </xsl:element>
  1513. </xsl:element>
  1514. </xsl:for-each>
  1515. </xsl:if>
  1516. </xsl:template>
  1517. <!-- ======================================================== -->
  1518. <!-- NCX templates are for backwards compatibility with EPUB2 -->
  1519. <!-- ======================================================== -->
  1520. <xsl:template name="ncx">
  1521. <xsl:message>Generating NCX file ...</xsl:message>
  1522. <xsl:call-template name="write.chunk">
  1523. <xsl:with-param name="filename">
  1524. <xsl:value-of select="$epub.ncx.pathname" />
  1525. </xsl:with-param>
  1526. <xsl:with-param name="method" select="'xml'" />
  1527. <xsl:with-param name="encoding" select="'utf-8'" />
  1528. <xsl:with-param name="indent" select="'no'" />
  1529. <xsl:with-param name="quiet" select="$chunk.quietly" />
  1530. <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
  1531. <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
  1532. <xsl:with-param name="content">
  1533. <xsl:element name="ncx" namespace="{$ncx.namespace}">
  1534. <xsl:attribute name="version">2005-1</xsl:attribute>
  1535. <!-- Via Martin Goerner: On covers: the IDPF2.0 standard unfortunately does not have a provision for
  1536. covers. We had to add one and we did so in conjunction with the IDPF and
  1537. various publishers. The tag chosen to define the covers is:
  1538. <meta name="cover" content="-reference to a manifest item-">
  1539. Then, we also added a bit of logic to get rid cleanly of the HTML cover
  1540. people usually add because the logical cover is not specced by the IDPF. So,
  1541. if the HTML cover item is marked linear="no" AND there is a guide item of
  1542. type="cover" pointing to it AND there is a logical cover specified in a
  1543. <meta name="cover"> tag, THEN, the HTML cover is discarded. -->
  1544. <xsl:element name="head" namespace="{$ncx.namespace}">
  1545. <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]">
  1546. <xsl:element name="meta" namespace="{$ncx.namespace}">
  1547. <xsl:attribute name="name">cover</xsl:attribute>
  1548. <xsl:attribute name="content">
  1549. <xsl:value-of select="$epub.cover.filename.id"/>
  1550. </xsl:attribute>
  1551. </xsl:element>
  1552. </xsl:if>
  1553. <xsl:element name="meta" namespace="{$ncx.namespace}">
  1554. <xsl:attribute name="name">dtb:uid</xsl:attribute>
  1555. <xsl:attribute name="content"><xsl:call-template name="package-identifier"/></xsl:attribute>
  1556. </xsl:element>
  1557. </xsl:element>
  1558. <xsl:choose>
  1559. <xsl:when test="$rootid != ''">
  1560. <xsl:variable name="title">
  1561. <xsl:if test="$epub.autolabel != 0">
  1562. <xsl:variable name="label.markup">
  1563. <xsl:apply-templates select="key('id',$rootid)" mode="label.markup" />
  1564. </xsl:variable>
  1565. <xsl:if test="normalize-space($label.markup)">
  1566. <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
  1567. </xsl:if>
  1568. </xsl:if>
  1569. <xsl:apply-templates select="key('id',$rootid)" mode="title.markup" />
  1570. </xsl:variable>
  1571. <xsl:variable name="href">
  1572. <xsl:call-template name="href.target.with.base.dir">
  1573. <xsl:with-param name="object" select="key('id',$rootid)" />
  1574. </xsl:call-template>
  1575. </xsl:variable>
  1576. <xsl:element name="docTitle" namespace="{$ncx.namespace}">
  1577. <xsl:element name="text" namespace="{$ncx.namespace}"><xsl:value-of select="normalize-space($title)" /> </xsl:element>
  1578. </xsl:element>
  1579. <xsl:element name="navMap" namespace="{$ncx.namespace}">
  1580. <xsl:apply-templates select="key('id',$rootid)/*" mode="ncx" />
  1581. </xsl:element>
  1582. </xsl:when>
  1583. <xsl:otherwise>
  1584. <xsl:variable name="title">
  1585. <xsl:if test="$epub.autolabel != 0">
  1586. <xsl:variable name="label.markup">
  1587. <xsl:apply-templates select="/*" mode="label.markup" />
  1588. </xsl:variable>
  1589. <xsl:if test="normalize-space($label.markup)">
  1590. <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
  1591. </xsl:if>
  1592. </xsl:if>
  1593. <xsl:apply-templates select="/*" mode="title.markup" />
  1594. </xsl:variable>
  1595. <xsl:variable name="href">
  1596. <xsl:call-template name="href.target.with.base.dir">
  1597. <xsl:with-param name="object" select="/" />
  1598. </xsl:call-template>
  1599. </xsl:variable>
  1600. <xsl:element name="docTitle" namespace="{$ncx.namespace}">
  1601. <xsl:element name="text" namespace="{$ncx.namespace}">
  1602. <xsl:value-of select="normalize-space($title)" />
  1603. </xsl:element>
  1604. </xsl:element>
  1605. <xsl:element name="navMap" namespace="{$ncx.namespace}">
  1606. <xsl:choose>
  1607. <xsl:when test="$root.is.a.chunk != '0'">
  1608. <xsl:apply-templates select="/*" mode="ncx" />
  1609. <xsl:apply-templates select="/*/*" mode="ncx" />
  1610. </xsl:when>
  1611. <xsl:otherwise>
  1612. <xsl:apply-templates select="/*/*" mode="ncx" />
  1613. </xsl:otherwise>
  1614. </xsl:choose>
  1615. </xsl:element>
  1616. </xsl:otherwise>
  1617. </xsl:choose>
  1618. </xsl:element>
  1619. </xsl:with-param>
  1620. </xsl:call-template>
  1621. </xsl:template>
  1622. <xsl:template match="book|
  1623. article|
  1624. topic|
  1625. part|
  1626. reference|
  1627. preface|
  1628. chapter|
  1629. bibliography|
  1630. appendix|
  1631. glossary|
  1632. section|
  1633. sect1|
  1634. sect2|
  1635. sect3|
  1636. sect4|
  1637. sect5|
  1638. refentry|
  1639. colophon|
  1640. bibliodiv[title]|
  1641. setindex|
  1642. index"
  1643. mode="ncx">
  1644. <xsl:variable name="depth" select="count(ancestor::*)"/>
  1645. <xsl:variable name="title">
  1646. <xsl:if test="$epub.autolabel != 0">
  1647. <xsl:variable name="label.markup">
  1648. <xsl:apply-templates select="." mode="label.markup" />
  1649. </xsl:variable>
  1650. <xsl:if test="normalize-space($label.markup)">
  1651. <xsl:value-of
  1652. select="concat($label.markup,$autotoc.label.separator)" />
  1653. </xsl:if>
  1654. </xsl:if>
  1655. <xsl:apply-templates select="." mode="title.markup" />
  1656. </xsl:variable>
  1657. <xsl:variable name="href">
  1658. <xsl:call-template name="href.target.with.base.dir">
  1659. <xsl:with-param name="context" select="/" />
  1660. <!-- Generate links relative to the location of root file/toc.xml file -->
  1661. </xsl:call-template>
  1662. </xsl:variable>
  1663. <xsl:variable name="id">
  1664. <xsl:value-of select="generate-id(.)"/>
  1665. </xsl:variable>
  1666. <xsl:variable name="order">
  1667. <xsl:value-of select="$depth +
  1668. count(preceding::part|
  1669. preceding::reference|
  1670. preceding::book[parent::set]|
  1671. preceding::preface|
  1672. preceding::chapter|
  1673. preceding::bibliography|
  1674. preceding::appendix|
  1675. preceding::article|
  1676. preceding::topic|
  1677. preceding::glossary|
  1678. preceding::section[not(parent::partintro)]|
  1679. preceding::sect1[not(parent::partintro)]|
  1680. preceding::sect2[not(ancestor::partintro)]|
  1681. preceding::sect3[not(ancestor::partintro)]|
  1682. preceding::sect4[not(ancestor::partintro)]|
  1683. preceding::sect5[not(ancestor::partintro)]|
  1684. preceding::refentry|
  1685. preceding::colophon|
  1686. preceding::bibliodiv[title]|
  1687. preceding::index)"/>
  1688. </xsl:variable>
  1689. <xsl:element name="navPoint" namespace="{$ncx.namespace}">
  1690. <xsl:attribute name="id">
  1691. <xsl:value-of select="$id"/>
  1692. </xsl:attribute>
  1693. <xsl:attribute name="playOrder">
  1694. <xsl:choose>
  1695. <xsl:when test="/*[self::set]">
  1696. <xsl:value-of select="$order"/>
  1697. </xsl:when>
  1698. <xsl:when test="$root.is.a.chunk != '0'">
  1699. <xsl:value-of select="$order + 1"/>
  1700. </xsl:when>
  1701. <xsl:otherwise>
  1702. <xsl:value-of select="$order - 0"/>
  1703. </xsl:otherwise>
  1704. </xsl:choose>
  1705. </xsl:attribute>
  1706. <xsl:element name="navLabel" namespace="{$ncx.namespace}">
  1707. <xsl:element name="text" namespace="{$ncx.namespace}"><xsl:value-of select="normalize-space($title)"/> </xsl:element>
  1708. </xsl:element>
  1709. <xsl:element name="content" namespace="{$ncx.namespace}">
  1710. <xsl:attribute name="src">
  1711. <xsl:value-of select="$href"/>
  1712. </xsl:attribute>
  1713. </xsl:element>
  1714. <xsl:if test="$depth != 0">
  1715. <!-- Don't recurse on root element, but treat it as a single point so
  1716. the progress bar shows all top level children -->
  1717. <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"/>
  1718. </xsl:if>
  1719. </xsl:element>
  1720. </xsl:template>
  1721. <xsl:template match="text()" mode="ncx" />
  1722. <xsl:template name="package.spine">
  1723. <xsl:variable name="toc.params">
  1724. <xsl:call-template name="find.path.params">
  1725. <xsl:with-param name="node" select="."/>
  1726. <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
  1727. </xsl:call-template>
  1728. </xsl:variable>
  1729. <xsl:element namespace="http://www.idpf.org/2007/opf" name="spine">
  1730. <xsl:if test="$epub.include.ncx != 0">
  1731. <xsl:attribute name="toc">
  1732. <xsl:value-of select="$epub.ncx.manifest.id"/>
  1733. </xsl:attribute>
  1734. </xsl:if>
  1735. <xsl:call-template name="spine.cover"/>
  1736. <xsl:if test="contains($toc.params, 'toc')">
  1737. <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
  1738. <xsl:attribute name="idref"> <xsl:value-of select="$epub.html.toc.id"/> </xsl:attribute>
  1739. <xsl:attribute name="linear">yes</xsl:attribute>
  1740. </xsl:element>
  1741. </xsl:if>
  1742. <!-- TODO: be nice to have a idref="titlepage" here -->
  1743. <xsl:choose>
  1744. <xsl:when test="$root.is.a.chunk != '0'">
  1745. <xsl:apply-templates select="/*" mode="package.spine"/>
  1746. </xsl:when>
  1747. <xsl:otherwise>
  1748. <xsl:apply-templates select="/*/*" mode="package.spine"/>
  1749. </xsl:otherwise>
  1750. </xsl:choose>
  1751. </xsl:element>
  1752. </xsl:template>
  1753. <xsl:template name="spine.cover">
  1754. <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
  1755. <xsl:variable name="cover.image"
  1756. select="$info//mediaobject[@role='cover' or ancestor::cover]"/>
  1757. <xsl:if test="$cover.image">
  1758. <!-- generate the spine reference to that cover html file -->
  1759. <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
  1760. <xsl:attribute name="idref">
  1761. <xsl:value-of select="$epub.cover.filename.id"/>
  1762. </xsl:attribute>
  1763. <xsl:attribute name="linear">
  1764. <xsl:choose>
  1765. <xsl:when test="$epub.cover.linear">
  1766. <xsl:text>yes</xsl:text>
  1767. </xsl:when>
  1768. <xsl:otherwise>no</xsl:otherwise>
  1769. </xsl:choose>
  1770. </xsl:attribute>
  1771. </xsl:element>
  1772. </xsl:if>
  1773. </xsl:template>
  1774. <xsl:template match="*" mode="package.spine">
  1775. <xsl:variable name="is.chunk">
  1776. <xsl:call-template name="chunk">
  1777. <xsl:with-param name="node" select="."/>
  1778. </xsl:call-template>
  1779. </xsl:variable>
  1780. <xsl:if test="$is.chunk != 0">
  1781. <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
  1782. <xsl:attribute name="idref">
  1783. <xsl:value-of select="concat($epub.package.id.prefix, generate-id(.))"/>
  1784. </xsl:attribute>
  1785. </xsl:element>
  1786. <xsl:apply-templates select="*|.//refentry" mode="package.spine"/>
  1787. </xsl:if>
  1788. </xsl:template>
  1789. <xsl:template match="*" mode="container">
  1790. <xsl:call-template name="container"/>
  1791. </xsl:template>
  1792. <xsl:template name="container">
  1793. <!-- The path in rootfile does not include all of base.dir, only the last part -->
  1794. <xsl:variable name="full-path-dir">
  1795. <xsl:call-template name="filename-basename">
  1796. <xsl:with-param name="filename" select="$chunk.base.dir"/>
  1797. </xsl:call-template>
  1798. </xsl:variable>
  1799. <xsl:call-template name="write.chunk">
  1800. <xsl:with-param name="filename">
  1801. <xsl:value-of select="$epub.container.pathname" />
  1802. </xsl:with-param>
  1803. <xsl:with-param name="method" select="'xml'" />
  1804. <xsl:with-param name="encoding" select="'utf-8'" />
  1805. <xsl:with-param name="indent" select="'no'" />
  1806. <xsl:with-param name="quiet" select="$chunk.quietly" />
  1807. <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
  1808. <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
  1809. <xsl:with-param name="content">
  1810. <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="container">
  1811. <xsl:attribute name="version">1.0</xsl:attribute>
  1812. <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="rootfiles">
  1813. <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="rootfile">
  1814. <xsl:attribute name="full-path">
  1815. <xsl:value-of
  1816. select="concat($full-path-dir, $epub.package.filename)"/>
  1817. </xsl:attribute>
  1818. <xsl:attribute name="media-type">
  1819. <xsl:text>application/oebps-package+xml</xsl:text>
  1820. </xsl:attribute>
  1821. </xsl:element>
  1822. </xsl:element>
  1823. </xsl:element>
  1824. </xsl:with-param>
  1825. </xsl:call-template>
  1826. </xsl:template>
  1827. <xsl:template name="mimetype">
  1828. <xsl:call-template name="write.text.chunk">
  1829. <xsl:with-param name="filename" select="$epub.mimetype.pathname"/>
  1830. <xsl:with-param name="content" select="$epub.mimetype.value"/>
  1831. </xsl:call-template>
  1832. </xsl:template>
  1833. <xsl:template match="mediaobject[@role='cover' or ancestor::cover]">
  1834. <xsl:call-template name="write.chunk">
  1835. <xsl:with-param name="filename">
  1836. <xsl:value-of select="$epub.cover.pathname" />
  1837. </xsl:with-param>
  1838. <xsl:with-param name="method" select="'xml'" />
  1839. <xsl:with-param name="encoding" select="'utf-8'" />
  1840. <xsl:with-param name="indent" select="'no'" />
  1841. <xsl:with-param name="quiet" select="$chunk.quietly" />
  1842. <xsl:with-param name="content">
  1843. <xsl:element namespace="http://www.w3.org/1999/xhtml" name="html">
  1844. <xsl:element namespace="http://www.w3.org/1999/xhtml" name="head">
  1845. <xsl:element namespace="http://www.w3.org/1999/xhtml" name="title">Cover</xsl:element>
  1846. <xsl:element namespace="http://www.w3.org/1999/xhtml" name="style">
  1847. <xsl:attribute name="type">text/css</xsl:attribute>
  1848. <!-- Help the cover image scale nicely in the CSS then apply a max-width to look better in Adobe Digital Editions -->
  1849. <xsl:text> img { max-width: 100%; }</xsl:text>
  1850. </xsl:element>
  1851. </xsl:element>
  1852. <xsl:element namespace="http://www.w3.org/1999/xhtml" name="body">
  1853. <xsl:element namespace="http://www.w3.org/1999/xhtml" name="div">
  1854. <xsl:attribute name="id">
  1855. <xsl:value-of select="$epub.cover.image.id"/>
  1856. </xsl:attribute>
  1857. <xsl:choose>
  1858. <xsl:when test="imageobject[@role='front-large']">
  1859. <xsl:apply-templates select="imageobject[@role='front-large']"/>
  1860. </xsl:when>
  1861. <xsl:otherwise>
  1862. <xsl:apply-templates select="imageobject[1]"/>
  1863. </xsl:otherwise>
  1864. </xsl:choose>
  1865. </xsl:element>
  1866. <!-- If this is defined as an explicit cover page, then process
  1867. any remaining text -->
  1868. <xsl:if test="ancestor::cover">
  1869. <xsl:apply-templates select="ancestor::cover/para"/>
  1870. </xsl:if>
  1871. </xsl:element>
  1872. </xsl:element>
  1873. </xsl:with-param>
  1874. </xsl:call-template>
  1875. </xsl:template>
  1876. <!-- EPUB3: use <nav> and <ol> in TOC lists -->
  1877. <xsl:template name="make.toc">
  1878. <xsl:param name="toc-context" select="."/>
  1879. <xsl:param name="toc.title.p" select="true()"/>
  1880. <xsl:param name="nodes" select="/NOT-AN-ELEMENT"/>
  1881. <xsl:variable name="nodes.plus" select="$nodes | qandaset"/>
  1882. <xsl:variable name="toc.title">
  1883. <xsl:if test="$toc.title.p">
  1884. <xsl:choose>
  1885. <xsl:when test="$make.clean.html != 0">
  1886. <div class="toc-title">
  1887. <xsl:call-template name="gentext">
  1888. <xsl:with-param name="key">TableofContents</xsl:with-param>
  1889. </xsl:call-template>
  1890. </div>
  1891. </xsl:when>
  1892. <xsl:otherwise>
  1893. <p>
  1894. <b>
  1895. <xsl:call-template name="gentext">
  1896. <xsl:with-param name="key">TableofContents</xsl:with-param>
  1897. </xsl:call-template>
  1898. </b>
  1899. </p>
  1900. </xsl:otherwise>
  1901. </xsl:choose>
  1902. </xsl:if>
  1903. </xsl:variable>
  1904. <xsl:choose>
  1905. <xsl:when test="$manual.toc != ''">
  1906. <xsl:variable name="id">
  1907. <xsl:call-template name="object.id"/>
  1908. </xsl:variable>
  1909. <xsl:variable name="toc" select="document($manual.toc, .)"/>
  1910. <xsl:variable name="tocentry" select="$toc//tocentry[@linkend=$id]"/>
  1911. <xsl:if test="$tocentry and $tocentry/*">
  1912. <div class="toc">
  1913. <xsl:copy-of select="$toc.title"/>
  1914. <nav epub:type="toc">
  1915. <xsl:element name="{$toc.list.type}">
  1916. <xsl:call-template name="manual-toc">
  1917. <xsl:with-param name="tocentry" select="$tocentry/*[1]"/>
  1918. </xsl:call-template>
  1919. </xsl:element>
  1920. </nav>
  1921. </div>
  1922. </xsl:if>
  1923. </xsl:when>
  1924. <xsl:otherwise>
  1925. <xsl:choose>
  1926. <xsl:when test="$qanda.in.toc != 0">
  1927. <div class="toc">
  1928. <xsl:copy-of select="$toc.title"/>
  1929. <nav epub:type="toc">
  1930. <xsl:element name="{$toc.list.type}">
  1931. <xsl:if test="$nodes.plus">
  1932. <xsl:apply-templates select="$nodes.plus" mode="toc">
  1933. <xsl:with-param name="toc-context" select="$toc-context"/>
  1934. </xsl:apply-templates>
  1935. </xsl:if>
  1936. </xsl:element>
  1937. </nav>
  1938. </div>
  1939. </xsl:when>
  1940. <xsl:otherwise>
  1941. <div class="toc">
  1942. <xsl:copy-of select="$toc.title"/>
  1943. <nav epub:type="toc">
  1944. <xsl:element name="{$toc.list.type}">
  1945. <xsl:if test="$nodes">
  1946. <xsl:apply-templates select="$nodes" mode="toc">
  1947. <xsl:with-param name="toc-context" select="$toc-context"/>
  1948. </xsl:apply-templates>
  1949. </xsl:if>
  1950. </xsl:element>
  1951. </nav>
  1952. </div>
  1953. </xsl:otherwise>
  1954. </xsl:choose>
  1955. </xsl:otherwise>
  1956. </xsl:choose>
  1957. </xsl:template>
  1958. <xsl:template name="list.of.titles">
  1959. <xsl:param name="toc-context" select="."/>
  1960. <xsl:param name="titles" select="'table'"/>
  1961. <xsl:param name="nodes" select=".//table"/>
  1962. <xsl:variable name="epub.type">
  1963. <xsl:choose>
  1964. <xsl:when test="$titles='table'">lot</xsl:when>
  1965. <xsl:when test="$titles='figure'">loi</xsl:when>
  1966. <xsl:when test="$titles='equation'">loi</xsl:when>
  1967. <xsl:when test="$titles='example'">loi</xsl:when>
  1968. <xsl:when test="$titles='procedure'">loi</xsl:when>
  1969. <xsl:otherwise>loi</xsl:otherwise>
  1970. </xsl:choose>
  1971. </xsl:variable>
  1972. <xsl:if test="$nodes">
  1973. <div class="list-of-{$titles}s">
  1974. <nav epub:type="{$epub.type}">
  1975. <h4 class="toc-title">
  1976. <xsl:call-template name="gentext">
  1977. <xsl:with-param name="key">
  1978. <xsl:choose>
  1979. <xsl:when test="$titles='table'">ListofTables</xsl:when>
  1980. <xsl:when test="$titles='figure'">ListofFigures</xsl:when>
  1981. <xsl:when test="$titles='equation'">ListofEquations</xsl:when>
  1982. <xsl:when test="$titles='example'">ListofExamples</xsl:when>
  1983. <xsl:when test="$titles='procedure'">ListofProcedures</xsl:when>
  1984. <xsl:otherwise>ListofUnknown</xsl:otherwise>
  1985. </xsl:choose>
  1986. </xsl:with-param>
  1987. </xsl:call-template>
  1988. </h4>
  1989. <xsl:element name="{$toc.list.type}">
  1990. <xsl:apply-templates select="$nodes" mode="toc">
  1991. <xsl:with-param name="toc-context" select="$toc-context"/>
  1992. </xsl:apply-templates>
  1993. </xsl:element>
  1994. </nav>
  1995. </div>
  1996. </xsl:if>
  1997. </xsl:template>
  1998. <!-- EPUB3: add hidden="" for sections below toc.section.depth -->
  1999. <xsl:template name="subtoc">
  2000. <xsl:param name="toc-context" select="."/>
  2001. <xsl:param name="nodes" select="NOT-AN-ELEMENT"/>
  2002. <xsl:variable name="nodes.plus" select="$nodes | qandaset"/>
  2003. <xsl:variable name="depth">
  2004. <xsl:choose>
  2005. <xsl:when test="local-name(.) = 'section'">
  2006. <xsl:value-of select="count(ancestor::section) + 1"/>
  2007. </xsl:when>
  2008. <xsl:when test="local-name(.) = 'sect1'">1</xsl:when>
  2009. <xsl:when test="local-name(.) = 'sect2'">2</xsl:when>
  2010. <xsl:when test="local-name(.) = 'sect3'">3</xsl:when>
  2011. <xsl:when test="local-name(.) = 'sect4'">4</xsl:when>
  2012. <xsl:when test="local-name(.) = 'sect5'">5</xsl:when>
  2013. <xsl:when test="local-name(.) = 'refsect1'">1</xsl:when>
  2014. <xsl:when test="local-name(.) = 'refsect2'">2</xsl:when>
  2015. <xsl:when test="local-name(.) = 'refsect3'">3</xsl:when>
  2016. <xsl:when test="local-name(.) = 'simplesect'">
  2017. <!-- sigh... -->
  2018. <xsl:choose>
  2019. <xsl:when test="local-name(..) = 'section'">
  2020. <xsl:value-of select="count(ancestor::section)"/>
  2021. </xsl:when>
  2022. <xsl:when test="local-name(..) = 'sect1'">2</xsl:when>
  2023. <xsl:when test="local-name(..) = 'sect2'">3</xsl:when>
  2024. <xsl:when test="local-name(..) = 'sect3'">4</xsl:when>
  2025. <xsl:when test="local-name(..) = 'sect4'">5</xsl:when>
  2026. <xsl:when test="local-name(..) = 'sect5'">6</xsl:when>
  2027. <xsl:when test="local-name(..) = 'refsect1'">2</xsl:when>
  2028. <xsl:when test="local-name(..) = 'refsect2'">3</xsl:when>
  2029. <xsl:when test="local-name(..) = 'refsect3'">4</xsl:when>
  2030. <xsl:otherwise>1</xsl:otherwise>
  2031. </xsl:choose>
  2032. </xsl:when>
  2033. <xsl:otherwise>0</xsl:otherwise>
  2034. </xsl:choose>
  2035. </xsl:variable>
  2036. <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
  2037. <xsl:variable name="subtoc">
  2038. <xsl:element name="{$toc.list.type}">
  2039. <xsl:choose>
  2040. <xsl:when test="$toc.listitem.type = 'li'
  2041. and $toc.section.depth > $depth and
  2042. ( ($qanda.in.toc = 0 and count($nodes)&gt;0) or
  2043. ($qanda.in.toc != 0 and count($nodes.plus)&gt;0) )
  2044. and $toc.max.depth > $depth.from.context">
  2045. <!-- No @hidden attribute -->
  2046. </xsl:when>
  2047. <xsl:otherwise>
  2048. <!-- Add empty @hidden attribute if too deep -->
  2049. <xsl:attribute name="hidden"></xsl:attribute>
  2050. </xsl:otherwise>
  2051. </xsl:choose>
  2052. <xsl:choose>
  2053. <xsl:when test="$qanda.in.toc != 0">
  2054. <xsl:apply-templates mode="toc" select="$nodes.plus">
  2055. <xsl:with-param name="toc-context" select="$toc-context"/>
  2056. </xsl:apply-templates>
  2057. </xsl:when>
  2058. <xsl:otherwise>
  2059. <xsl:apply-templates mode="toc" select="$nodes">
  2060. <xsl:with-param name="toc-context" select="$toc-context"/>
  2061. </xsl:apply-templates>
  2062. </xsl:otherwise>
  2063. </xsl:choose>
  2064. </xsl:element>
  2065. </xsl:variable>
  2066. <xsl:variable name="subtoc.list">
  2067. <xsl:choose>
  2068. <xsl:when test="$toc.dd.type = ''">
  2069. <xsl:copy-of select="$subtoc"/>
  2070. </xsl:when>
  2071. <xsl:otherwise>
  2072. <xsl:element name="{$toc.dd.type}">
  2073. <xsl:copy-of select="$subtoc"/>
  2074. </xsl:element>
  2075. </xsl:otherwise>
  2076. </xsl:choose>
  2077. </xsl:variable>
  2078. <xsl:element name="{$toc.listitem.type}">
  2079. <xsl:call-template name="toc.line">
  2080. <xsl:with-param name="toc-context" select="$toc-context"/>
  2081. </xsl:call-template>
  2082. <xsl:if test="$toc.listitem.type = 'li'
  2083. and
  2084. ( ($qanda.in.toc = 0 and count($nodes)&gt;0) or
  2085. ($qanda.in.toc != 0 and count($nodes.plus)&gt;0) ) ">
  2086. <xsl:copy-of select="$subtoc.list"/>
  2087. </xsl:if>
  2088. </xsl:element>
  2089. </xsl:template>
  2090. <!-- Inserted when a title is blank to avoid epubcheck error -->
  2091. <xsl:param name="toc.entry.default.text">&#xA0;</xsl:param>
  2092. <!-- EPUB3: either <a> or <span>, but not both -->
  2093. <xsl:template name="toc.line">
  2094. <xsl:param name="toc-context" select="."/>
  2095. <xsl:param name="depth" select="1"/>
  2096. <xsl:param name="depth.from.context" select="8"/>
  2097. <xsl:variable name="title">
  2098. <xsl:apply-templates select="." mode="title.markup"/>
  2099. </xsl:variable>
  2100. <a>
  2101. <xsl:attribute name="href">
  2102. <xsl:call-template name="href.target">
  2103. <xsl:with-param name="context" select="$toc-context"/>
  2104. <xsl:with-param name="toc-context" select="$toc-context"/>
  2105. </xsl:call-template>
  2106. </xsl:attribute>
  2107. <!-- * if $autotoc.label.in.hyperlink is non-zero, then output the label -->
  2108. <!-- * as part of the hyperlinked title -->
  2109. <xsl:if test="not($autotoc.label.in.hyperlink = 0)">
  2110. <xsl:variable name="label">
  2111. <xsl:apply-templates select="." mode="label.markup"/>
  2112. </xsl:variable>
  2113. <xsl:copy-of select="$label"/>
  2114. <xsl:if test="$label != ''">
  2115. <xsl:value-of select="$autotoc.label.separator"/>
  2116. </xsl:if>
  2117. </xsl:if>
  2118. <xsl:choose>
  2119. <xsl:when test="string-length(normalize-space($title)) != 0">
  2120. <xsl:copy-of select="$title"/>
  2121. </xsl:when>
  2122. <xsl:otherwise>
  2123. <xsl:value-of select="$toc.entry.default.text"/>
  2124. </xsl:otherwise>
  2125. </xsl:choose>
  2126. </a>
  2127. </xsl:template>
  2128. <!-- Make sure all text is inside the <a> element for epub3 -->
  2129. <xsl:template match="figure|table|example|equation|procedure" mode="toc">
  2130. <xsl:param name="toc-context" select="."/>
  2131. <xsl:element name="{$toc.listitem.type}">
  2132. <a>
  2133. <xsl:attribute name="href">
  2134. <xsl:call-template name="href.target">
  2135. <xsl:with-param name="toc-context" select="$toc-context"/>
  2136. </xsl:call-template>
  2137. </xsl:attribute>
  2138. <xsl:variable name="label">
  2139. <xsl:apply-templates select="." mode="label.markup"/>
  2140. </xsl:variable>
  2141. <xsl:copy-of select="$label"/>
  2142. <xsl:if test="$label != ''">
  2143. <xsl:value-of select="$autotoc.label.separator"/>
  2144. </xsl:if>
  2145. <xsl:apply-templates select="." mode="titleabbrev.markup"/>
  2146. </a>
  2147. </xsl:element>
  2148. </xsl:template>
  2149. <!-- Remove spans from refentry TOC lines for epub3check -->
  2150. <xsl:template match="refentry" mode="toc">
  2151. <xsl:param name="toc-context" select="."/>
  2152. <xsl:variable name="refmeta" select=".//refmeta"/>
  2153. <xsl:variable name="refentrytitle" select="$refmeta//refentrytitle"/>
  2154. <xsl:variable name="refnamediv" select=".//refnamediv"/>
  2155. <xsl:variable name="refname" select="$refnamediv//refname"/>
  2156. <xsl:variable name="refdesc" select="$refnamediv//refdescriptor"/>
  2157. <xsl:variable name="title">
  2158. <xsl:choose>
  2159. <xsl:when test="$refentrytitle">
  2160. <xsl:apply-templates select="$refentrytitle[1]" mode="titleabbrev.markup"/>
  2161. </xsl:when>
  2162. <xsl:when test="$refdesc">
  2163. <xsl:apply-templates select="$refdesc" mode="titleabbrev.markup"/>
  2164. </xsl:when>
  2165. <xsl:when test="$refname">
  2166. <xsl:apply-templates select="$refname[1]" mode="titleabbrev.markup"/>
  2167. </xsl:when>
  2168. </xsl:choose>
  2169. </xsl:variable>
  2170. <xsl:element name="{$toc.listitem.type}" namespace="http://www.w3.org/1999/xhtml">
  2171. <a>
  2172. <xsl:attribute name="href">
  2173. <xsl:call-template name="href.target">
  2174. <xsl:with-param name="toc-context" select="$toc-context"/>
  2175. </xsl:call-template>
  2176. </xsl:attribute>
  2177. <xsl:copy-of select="$title"/>
  2178. <xsl:if test="$annotate.toc != 0">
  2179. <!-- * DocBook 5 says inlinemediaobject (among other things) -->
  2180. <!-- * is allowed in refpurpose; so we need to run -->
  2181. <!-- * apply-templates on refpurpose here, instead of value-of -->
  2182. <!-- Set allow-anchors=0 to avoid indexterms and other links -->
  2183. <xsl:text> - </xsl:text>
  2184. <xsl:apply-templates select="refnamediv/refpurpose" mode="no.anchor.mode"/>
  2185. </xsl:if>
  2186. </a>
  2187. </xsl:element>
  2188. </xsl:template>
  2189. <!-- Copy these here so relative document() open gets the correct css source -->
  2190. <xsl:template name="generate.default.css.file">
  2191. <xsl:if test="$make.clean.html != 0 and
  2192. $generate.css.header = 0 and
  2193. $docbook.css.source != ''">
  2194. <!-- Select default file relative to stylesheet -->
  2195. <xsl:variable name="css.node" select="document($docbook.css.source)/*[1]"/>
  2196. <xsl:call-template name="generate.css.file">
  2197. <xsl:with-param name="src" select="$docbook.css.source"/>
  2198. <xsl:with-param name="css.node" select="$css.node"/>
  2199. </xsl:call-template>
  2200. </xsl:if>
  2201. </xsl:template>
  2202. <xsl:template name="generate.custom.css.file">
  2203. <xsl:if test="$custom.css.source != '' and
  2204. $generate.css.header = 0">
  2205. <!-- Select custom file relative to document -->
  2206. <xsl:variable name="css.node" select="document($custom.css.source,.)/*[1]"/>
  2207. <xsl:call-template name="generate.css.file">
  2208. <xsl:with-param name="src" select="$custom.css.source"/>
  2209. <xsl:with-param name="css.node" select="$css.node"/>
  2210. </xsl:call-template>
  2211. </xsl:if>
  2212. </xsl:template>
  2213. </xsl:stylesheet>