docbook.xsl 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet
  3. xmlns:db="http://docbook.org/ns/docbook"
  4. xmlns:dc="http://purl.org/dc/elements/1.1/"
  5. xmlns:exsl="http://exslt.org/common"
  6. xmlns:h="http://www.w3.org/1999/xhtml"
  7. xmlns:ncx="http://www.daisy.org/z3986/2005/ncx/"
  8. xmlns:ng="http://docbook.org/docbook-ng"
  9. xmlns:opf="http://www.idpf.org/2007/opf"
  10. xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
  11. xmlns:str="http://exslt.org/strings"
  12. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  13. xmlns:xtext="xalan://com.nwalsh.xalan.Text"
  14. extension-element-prefixes="stext xtext"
  15. exclude-result-prefixes="exsl db dc h ncx ng opf stext str xtext"
  16. version="1.0">
  17. <xsl:import href="../xhtml-1_1/docbook.xsl" />
  18. <xsl:import href="../xhtml-1_1/chunk-common.xsl" />
  19. <xsl:include href="../xhtml-1_1/chunk-code.xsl" />
  20. <!-- We want a separate TOC file, please -->
  21. <xsl:param name="chunk.tocs.and.lots">1</xsl:param>
  22. <xsl:param name="toc.section.depth">2</xsl:param>
  23. <xsl:param name="generate.toc">
  24. book toc,title
  25. </xsl:param>
  26. <xsl:param name="ade.extensions" select="0"/>
  27. <xsl:param name="epub.autolabel" select="'1'"/>
  28. <xsl:param name="epub.ncx.depth">4</xsl:param> <!-- Not functional until http://code.google.com/p/epubcheck/issues/detail?id=70 is resolved -->
  29. <xsl:param name="manifest.in.base.dir" select="'1'"/>
  30. <xsl:param name="base.dir" select="$epub.oebps.dir"/>
  31. <xsl:param name="epub.oebps.dir" select="'OEBPS/'"/>
  32. <xsl:param name="epub.ncx.filename" select="'toc.ncx'"/>
  33. <xsl:param name="epub.container.filename" select="'container.xml'"/>
  34. <xsl:param name="epub.opf.filename" select="concat($epub.oebps.dir, 'content.opf')"/>
  35. <xsl:param name="epub.cover.filename" select="concat($epub.oebps.dir, 'cover', $html.ext)"/>
  36. <xsl:param name="epub.cover.id" select="'cover'"/>
  37. <xsl:param name="epub.cover.html" select="'cover.html'" />
  38. <xsl:param name="epub.cover.image.id" select="'cover-image'"/>
  39. <xsl:param name="epub.cover.linear" select="0" />
  40. <xsl:param name="epub.ncx.toc.id">ncxtoc</xsl:param>
  41. <xsl:param name="epub.html.toc.id">htmltoc</xsl:param>
  42. <xsl:param name="epub.metainf.dir" select="'META-INF/'"/>
  43. <xsl:param name="epub.embedded.fonts"></xsl:param>
  44. <!-- Turning this on crashes ADE, which is unbelievably awesome -->
  45. <xsl:param name="formal.object.break.after">0</xsl:param>
  46. <!-- Per Bob Stayton:
  47. """Process your documents with the css.decoration parameter set to zero.
  48. That will avoid the use of style attributes in XHTML elements where they are not permitted."""
  49. http://www.sagehill.net/docbookxsl/OtherOutputForms.html#StrictXhtmlValid -->
  50. <xsl:param name="css.decoration" select="0"/>
  51. <xsl:param name="custom.css.source"></xsl:param> <!-- FIXME: Align with current CSS parameter design -->
  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. <!-- no navigation in .epub -->
  57. <xsl:param name="suppress.navigation" select="'1'"/>
  58. <xsl:variable name="toc.params">
  59. <xsl:call-template name="find.path.params">
  60. <xsl:with-param name="node" select="/*"/>
  61. <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
  62. </xsl:call-template>
  63. </xsl:variable>
  64. <xsl:variable name="root.is.a.chunk">
  65. <xsl:choose>
  66. <xsl:when test="/*[not(self::book)][not(sect1) or not(section)]">
  67. <xsl:text>1</xsl:text>
  68. </xsl:when>
  69. <xsl:when test="/book[*[last()][self::bookinfo]]|book[bookinfo]">
  70. <xsl:text>1</xsl:text>
  71. </xsl:when>
  72. <xsl:when test="/book[*[last()][self::info]]|book[info]">
  73. <xsl:text>1</xsl:text>
  74. </xsl:when>
  75. <xsl:when test="/bibliography">
  76. <xsl:text>1</xsl:text>
  77. </xsl:when>
  78. <xsl:otherwise>
  79. <xsl:text>0</xsl:text>
  80. </xsl:otherwise>
  81. </xsl:choose>
  82. </xsl:variable>
  83. <xsl:key name="image-filerefs" match="graphic|inlinegraphic|imagedata" use="@fileref"/>
  84. <xsl:template match="/" priority="1">
  85. <!-- * Get a title for current doc so that we let the user -->
  86. <!-- * know what document we are processing at this point. -->
  87. <xsl:variable name="doc.title">
  88. <xsl:call-template name="get.doc.title" />
  89. </xsl:variable>
  90. <xsl:choose>
  91. <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
  92. toss the namespace and continue. Use the docbook5 namespaced
  93. stylesheets for DocBook5 if you don't want to use this feature.-->
  94. <!-- include extra test for Xalan quirk -->
  95. <xsl:when test="$exsl.node.set.available != 0
  96. and (*/self::ng:* or */self::db:*)">
  97. <xsl:call-template name="log.message">
  98. <xsl:with-param name="level">Note</xsl:with-param>
  99. <xsl:with-param name="source" select="$doc.title" />
  100. <xsl:with-param name="context-desc">
  101. <xsl:text>namesp. cut</xsl:text>
  102. </xsl:with-param>
  103. <xsl:with-param name="message">
  104. <xsl:text>stripped namespace before processing</xsl:text>
  105. </xsl:with-param>
  106. </xsl:call-template>
  107. <xsl:variable name="nons">
  108. <xsl:apply-templates mode="stripNS" />
  109. </xsl:variable>
  110. <xsl:call-template name="log.message">
  111. <xsl:with-param name="level">Note</xsl:with-param>
  112. <xsl:with-param name="source" select="$doc.title" />
  113. <xsl:with-param name="context-desc">
  114. <xsl:text>namesp. cut</xsl:text>
  115. </xsl:with-param>
  116. <xsl:with-param name="message">
  117. <xsl:text>processing stripped document</xsl:text>
  118. </xsl:with-param>
  119. </xsl:call-template>
  120. <xsl:apply-templates select="exsl:node-set($nons)" />
  121. </xsl:when>
  122. <xsl:otherwise>
  123. <xsl:choose>
  124. <xsl:when test="$rootid != ''">
  125. <xsl:choose>
  126. <xsl:when
  127. test="count(key('id',$rootid)) = 0">
  128. <xsl:message terminate="yes">
  129. <xsl:text>ID '</xsl:text>
  130. <xsl:value-of select="$rootid" />
  131. <xsl:text>' not found in document.</xsl:text>
  132. </xsl:message>
  133. </xsl:when>
  134. <xsl:otherwise>
  135. <xsl:if
  136. test="$collect.xref.targets = 'yes' or
  137. $collect.xref.targets = 'only'">
  138. <xsl:apply-templates
  139. select="key('id', $rootid)" mode="collect.targets" />
  140. </xsl:if>
  141. <xsl:if
  142. test="$collect.xref.targets != 'only'">
  143. <xsl:message>
  144. Formatting from
  145. <xsl:value-of select="$rootid" />
  146. </xsl:message>
  147. <xsl:apply-templates
  148. select="key('id',$rootid)" mode="process.root" />
  149. <xsl:call-template name="ncx" />
  150. </xsl:if>
  151. </xsl:otherwise>
  152. </xsl:choose>
  153. </xsl:when>
  154. <xsl:otherwise>
  155. <xsl:if
  156. test="$collect.xref.targets = 'yes' or
  157. $collect.xref.targets = 'only'">
  158. <xsl:apply-templates select="/"
  159. mode="collect.targets" />
  160. </xsl:if>
  161. <xsl:if
  162. test="$collect.xref.targets != 'only'">
  163. <xsl:apply-templates select="/"
  164. mode="process.root" />
  165. <xsl:call-template name="ncx" />
  166. <xsl:call-template name="opf" />
  167. <xsl:call-template name="cover" />
  168. <xsl:call-template name="container" />
  169. </xsl:if>
  170. </xsl:otherwise>
  171. </xsl:choose>
  172. </xsl:otherwise>
  173. </xsl:choose>
  174. </xsl:template>
  175. <xsl:template name="package-identifier">
  176. <xsl:choose>
  177. <xsl:when test="/*/*[contains(name(.), 'info')]/biblioid">
  178. <xsl:if test="/*/*[contains(name(.), 'info')][1]/biblioid[1][@class = 'doi' or
  179. @class = 'isbn' or
  180. @class = 'isrn' or
  181. @class = 'issn']">
  182. <xsl:text>urn:</xsl:text>
  183. <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/biblioid[1]/@class"/>
  184. <xsl:text>:</xsl:text>
  185. </xsl:if>
  186. <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/biblioid[1]"/>
  187. </xsl:when>
  188. <xsl:when test="/*/*[contains(name(.), 'info')]/isbn">
  189. <xsl:text>urn:isbn:</xsl:text>
  190. <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/isbn[1]"/>
  191. </xsl:when>
  192. <xsl:when test="/*/*[contains(name(.), 'info')]/issn">
  193. <xsl:text>urn:issn:</xsl:text>
  194. <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/issn[1]"/>
  195. </xsl:when>
  196. <xsl:otherwise>
  197. <xsl:choose>
  198. <xsl:when test="/*/*[contains(name(.), 'info')]/invpartnumber"> <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/invpartnumber[1]"/> </xsl:when>
  199. <xsl:when test="/*/*[contains(name(.), 'info')]/issuenum"> <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/issuenum[1]"/> </xsl:when>
  200. <xsl:when test="/*/*[contains(name(.), 'info')]/productnumber"> <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/productnumber[1]"/> </xsl:when>
  201. <xsl:when test="/*/*[contains(name(.), 'info')]/seriesvolnums"> <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/seriesvolnums[1]"/> </xsl:when>
  202. <xsl:when test="/*/*[contains(name(.), 'info')]/volumenum"> <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/volumenum[1]"/> </xsl:when>
  203. <!-- Deprecated -->
  204. <xsl:when test="/*/*[contains(name(.), 'info')]/pubsnumber"> <xsl:value-of select="/*/*[contains(name(.), 'info')][1]/pubsnumber[1]"/> </xsl:when>
  205. </xsl:choose>
  206. <xsl:text>_</xsl:text>
  207. <xsl:choose>
  208. <xsl:when test="/*/@id">
  209. <xsl:value-of select="/*/@id"/>
  210. </xsl:when>
  211. <xsl:when test="/*/@xml:id">
  212. <xsl:value-of select="/*/@xml:id"/>
  213. </xsl:when>
  214. <xsl:otherwise>
  215. <!-- TODO: Do UUIDs here -->
  216. <xsl:value-of select="generate-id(/*)"/>
  217. </xsl:otherwise>
  218. </xsl:choose>
  219. </xsl:otherwise>
  220. </xsl:choose>
  221. </xsl:template>
  222. <xsl:template name="opf">
  223. <xsl:variable name="package-identifier-id"><xsl:value-of select="concat(name(/*), 'id')"/></xsl:variable>
  224. <xsl:variable name="doc.title">
  225. <xsl:call-template name="get.doc.title" />
  226. </xsl:variable>
  227. <xsl:call-template name="write.chunk">
  228. <xsl:with-param name="filename">
  229. <xsl:value-of select="$epub.opf.filename" />
  230. </xsl:with-param>
  231. <xsl:with-param name="method" select="'xml'" />
  232. <xsl:with-param name="encoding" select="'utf-8'" />
  233. <xsl:with-param name="indent" select="'no'" />
  234. <xsl:with-param name="quiet" select="$chunk.quietly" />
  235. <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
  236. <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
  237. <xsl:with-param name="content">
  238. <xsl:element namespace="http://www.idpf.org/2007/opf" name="package">
  239. <xsl:attribute name="version">2.0</xsl:attribute>
  240. <xsl:attribute name="unique-identifier"> <xsl:value-of select="$package-identifier-id"/> </xsl:attribute>
  241. <xsl:element namespace="http://www.idpf.org/2007/opf" name="metadata">
  242. <xsl:element name="dc:identifier">
  243. <xsl:attribute name="id"><xsl:value-of select="$package-identifier-id"/></xsl:attribute>
  244. <xsl:call-template name="package-identifier"/>
  245. </xsl:element>
  246. <xsl:element name="dc:title">
  247. <xsl:value-of select="normalize-space($doc.title)"/>
  248. </xsl:element>
  249. <xsl:apply-templates select="/*/*[contains(name(.), 'info')]/*"
  250. mode="opf.metadata"/>
  251. <xsl:element name="dc:language">
  252. <xsl:call-template name="l10n.language">
  253. <xsl:with-param name="target" select="/*"/>
  254. </xsl:call-template>
  255. </xsl:element>
  256. <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]">
  257. <xsl:element namespace="http://www.idpf.org/2007/opf" name="meta">
  258. <xsl:attribute name="name">cover</xsl:attribute>
  259. <xsl:attribute name="content">
  260. <xsl:value-of select="$epub.cover.image.id"/>
  261. </xsl:attribute>
  262. </xsl:element>
  263. </xsl:if>
  264. </xsl:element>
  265. <xsl:call-template name="opf.manifest"/>
  266. <xsl:call-template name="opf.spine"/>
  267. <xsl:call-template name="opf.guide"/>
  268. </xsl:element>
  269. </xsl:with-param>
  270. </xsl:call-template>
  271. </xsl:template>
  272. <xsl:template name="container">
  273. <xsl:call-template name="write.chunk">
  274. <xsl:with-param name="filename">
  275. <xsl:value-of select="$epub.metainf.dir" />
  276. <xsl:value-of select="$epub.container.filename" />
  277. </xsl:with-param>
  278. <xsl:with-param name="method" select="'xml'" />
  279. <xsl:with-param name="encoding" select="'utf-8'" />
  280. <xsl:with-param name="indent" select="'no'" />
  281. <xsl:with-param name="quiet" select="$chunk.quietly" />
  282. <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
  283. <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
  284. <xsl:with-param name="content">
  285. <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="container">
  286. <xsl:attribute name="version">1.0</xsl:attribute>
  287. <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="rootfiles">
  288. <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="rootfile">
  289. <xsl:attribute name="full-path">
  290. <xsl:value-of select="$epub.opf.filename" />
  291. </xsl:attribute>
  292. <xsl:attribute name="media-type">
  293. <xsl:text>application/oebps-package+xml</xsl:text>
  294. </xsl:attribute>
  295. </xsl:element>
  296. </xsl:element>
  297. </xsl:element>
  298. </xsl:with-param>
  299. </xsl:call-template>
  300. </xsl:template>
  301. <xsl:template name="ncx">
  302. <xsl:call-template name="write.chunk">
  303. <xsl:with-param name="filename">
  304. <xsl:if test="$manifest.in.base.dir != 0">
  305. <xsl:value-of select="$chunk.base.dir" />
  306. </xsl:if>
  307. <xsl:value-of select="$epub.ncx.filename" />
  308. </xsl:with-param>
  309. <xsl:with-param name="method" select="'xml'" />
  310. <xsl:with-param name="encoding" select="'utf-8'" />
  311. <xsl:with-param name="indent" select="'no'" />
  312. <xsl:with-param name="quiet" select="$chunk.quietly" />
  313. <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
  314. <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
  315. <xsl:with-param name="content">
  316. <xsl:element name="ncx" namespace="http://www.daisy.org/z3986/2005/ncx/">
  317. <xsl:attribute name="version">2005-1</xsl:attribute>
  318. <!-- Via Martin Goerner: On covers: the IDPF2.0 standard unfortunately does not have a provision for
  319. covers. We had to add one and we did so in conjunction with the IDPF and
  320. various publishers. The tag chosen to define the covers is:
  321. <meta name="cover" content="-reference to a manifest item-">
  322. Then, we also added a bit of logic to get rid cleanly of the HTML cover
  323. people usually add because the logical cover is not specced by the IDPF. So,
  324. if the HTML cover item is marked linear="no" AND there is a guide item of
  325. type="cover" pointing to it AND there is a logical cover specified in a
  326. <meta name="cover"> tag, THEN, the HTML cover is discarded. -->
  327. <xsl:element name="head" namespace="http://www.daisy.org/z3986/2005/ncx/">
  328. <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]">
  329. <xsl:element name="meta" namespace="http://www.daisy.org/z3986/2005/ncx/">
  330. <xsl:attribute name="name">cover</xsl:attribute>
  331. <xsl:attribute name="content">
  332. <xsl:value-of select="$epub.cover.id"/>
  333. </xsl:attribute>
  334. </xsl:element>
  335. </xsl:if>
  336. <xsl:element name="meta" namespace="http://www.daisy.org/z3986/2005/ncx/">
  337. <xsl:attribute name="name">dtb:uid</xsl:attribute>
  338. <xsl:attribute name="content"><xsl:call-template name="package-identifier"/></xsl:attribute>
  339. </xsl:element>
  340. </xsl:element>
  341. <xsl:choose>
  342. <xsl:when test="$rootid != ''">
  343. <xsl:variable name="title">
  344. <xsl:if test="$epub.autolabel != 0">
  345. <xsl:variable name="label.markup">
  346. <xsl:apply-templates select="key('id',$rootid)" mode="label.markup" />
  347. </xsl:variable>
  348. <xsl:if test="normalize-space($label.markup)">
  349. <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
  350. </xsl:if>
  351. </xsl:if>
  352. <xsl:apply-templates select="key('id',$rootid)" mode="title.markup" />
  353. </xsl:variable>
  354. <xsl:variable name="href">
  355. <xsl:call-template name="href.target.with.base.dir">
  356. <xsl:with-param name="object" select="key('id',$rootid)" />
  357. </xsl:call-template>
  358. </xsl:variable>
  359. <xsl:element name="docTitle" namespace="http://www.daisy.org/z3986/2005/ncx/">
  360. <xsl:element name="text" namespace="http://www.daisy.org/z3986/2005/ncx/"><xsl:value-of select="normalize-space($title)" /> </xsl:element>
  361. </xsl:element>
  362. <xsl:element name="navMap" namespace="http://www.daisy.org/z3986/2005/ncx/">
  363. <xsl:apply-templates select="key('id',$rootid)/*" mode="ncx" />
  364. </xsl:element>
  365. </xsl:when>
  366. <xsl:otherwise>
  367. <xsl:variable name="title">
  368. <xsl:if test="$epub.autolabel != 0">
  369. <xsl:variable name="label.markup">
  370. <xsl:apply-templates select="/*" mode="label.markup" />
  371. </xsl:variable>
  372. <xsl:if test="normalize-space($label.markup)">
  373. <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
  374. </xsl:if>
  375. </xsl:if>
  376. <xsl:apply-templates select="/*" mode="title.markup" />
  377. </xsl:variable>
  378. <xsl:variable name="href">
  379. <xsl:call-template name="href.target.with.base.dir">
  380. <xsl:with-param name="object" select="/" />
  381. </xsl:call-template>
  382. </xsl:variable>
  383. <xsl:element name="docTitle" namespace="http://www.daisy.org/z3986/2005/ncx/">
  384. <xsl:element name="text" namespace="http://www.daisy.org/z3986/2005/ncx/">
  385. <xsl:value-of select="normalize-space($title)" />
  386. </xsl:element>
  387. </xsl:element>
  388. <xsl:element name="navMap" namespace="http://www.daisy.org/z3986/2005/ncx/">
  389. <xsl:choose>
  390. <xsl:when test="$root.is.a.chunk != '0'">
  391. <xsl:apply-templates select="/*" mode="ncx" />
  392. </xsl:when>
  393. <xsl:otherwise>
  394. <xsl:apply-templates select="/*/*" mode="ncx" />
  395. </xsl:otherwise>
  396. </xsl:choose>
  397. </xsl:element>
  398. </xsl:otherwise>
  399. </xsl:choose>
  400. </xsl:element>
  401. </xsl:with-param>
  402. </xsl:call-template>
  403. </xsl:template>
  404. <xsl:template match="book|
  405. article|
  406. part|
  407. reference|
  408. preface|
  409. chapter|
  410. bibliography|
  411. appendix|
  412. glossary|
  413. section|
  414. sect1|
  415. sect2|
  416. sect3|
  417. sect4|
  418. sect5|
  419. refentry|
  420. colophon|
  421. bibliodiv[title]|
  422. setindex|
  423. index"
  424. mode="ncx">
  425. <xsl:variable name="depth" select="count(ancestor::*)"/>
  426. <xsl:variable name="title">
  427. <xsl:if test="$epub.autolabel != 0">
  428. <xsl:variable name="label.markup">
  429. <xsl:apply-templates select="." mode="label.markup" />
  430. </xsl:variable>
  431. <xsl:if test="normalize-space($label.markup)">
  432. <xsl:value-of
  433. select="concat($label.markup,$autotoc.label.separator)" />
  434. </xsl:if>
  435. </xsl:if>
  436. <xsl:apply-templates select="." mode="title.markup" />
  437. </xsl:variable>
  438. <xsl:variable name="href">
  439. <xsl:call-template name="href.target.with.base.dir">
  440. <xsl:with-param name="context" select="/" />
  441. <!-- Generate links relative to the location of root file/toc.xml file -->
  442. </xsl:call-template>
  443. </xsl:variable>
  444. <xsl:variable name="id">
  445. <xsl:value-of select="generate-id(.)"/>
  446. </xsl:variable>
  447. <xsl:variable name="order">
  448. <xsl:value-of select="$depth +
  449. count(preceding::part|
  450. preceding::reference|
  451. preceding::book[parent::set]|
  452. preceding::preface|
  453. preceding::chapter|
  454. preceding::bibliography|
  455. preceding::appendix|
  456. preceding::article|
  457. preceding::glossary|
  458. preceding::section[not(parent::partintro)]|
  459. preceding::sect1[not(parent::partintro)]|
  460. preceding::sect2[not(ancestor::partintro)]|
  461. preceding::sect3[not(ancestor::partintro)]|
  462. preceding::sect4[not(ancestor::partintro)]|
  463. preceding::sect5[not(ancestor::partintro)]|
  464. preceding::refentry|
  465. preceding::colophon|
  466. preceding::bibliodiv[title]|
  467. preceding::index)"/>
  468. </xsl:variable>
  469. <xsl:element name="navPoint" namespace="http://www.daisy.org/z3986/2005/ncx/">
  470. <xsl:attribute name="id">
  471. <xsl:value-of select="$id"/>
  472. </xsl:attribute>
  473. <xsl:attribute name="playOrder">
  474. <xsl:choose>
  475. <xsl:when test="/*[self::set]">
  476. <xsl:value-of select="$order"/>
  477. </xsl:when>
  478. <xsl:when test="$root.is.a.chunk != '0'">
  479. <xsl:value-of select="$order + 1"/>
  480. </xsl:when>
  481. <xsl:otherwise>
  482. <xsl:value-of select="$order - 0"/>
  483. </xsl:otherwise>
  484. </xsl:choose>
  485. </xsl:attribute>
  486. <xsl:element name="navLabel" namespace="http://www.daisy.org/z3986/2005/ncx/">
  487. <xsl:element name="text" namespace="http://www.daisy.org/z3986/2005/ncx/"><xsl:value-of select="normalize-space($title)"/> </xsl:element>
  488. </xsl:element>
  489. <xsl:element name="content" namespace="http://www.daisy.org/z3986/2005/ncx/">
  490. <xsl:attribute name="src">
  491. <xsl:value-of select="$href"/>
  492. </xsl:attribute>
  493. </xsl:element>
  494. <xsl:apply-templates select="book[parent::set]|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv[title]|setindex|index" mode="ncx"/>
  495. </xsl:element>
  496. </xsl:template>
  497. <xsl:template match="*" mode="opf.metadata">
  498. <!-- override if you care -->
  499. </xsl:template>
  500. <xsl:template match="authorgroup" mode="opf.metadata">
  501. <xsl:apply-templates select="author|corpauthor" mode="opf.metadata"/>
  502. </xsl:template>
  503. <xsl:template match="author|corpauthor" mode="opf.metadata">
  504. <xsl:variable name="n">
  505. <xsl:call-template name="person.name">
  506. <xsl:with-param name="node" select="."/>
  507. </xsl:call-template>
  508. </xsl:variable>
  509. <xsl:element name="dc:creator">
  510. <xsl:attribute name="opf:file-as">
  511. <xsl:call-template name="person.name.last-first">
  512. <xsl:with-param name="node" select="."/>
  513. </xsl:call-template>
  514. </xsl:attribute>
  515. <xsl:value-of select="normalize-space(string($n))"/>
  516. </xsl:element>
  517. </xsl:template>
  518. <xsl:template match="date" mode="opf.metadata">
  519. <xsl:element name="dc:date">
  520. <xsl:value-of select="normalize-space(string(.))"/>
  521. </xsl:element>
  522. </xsl:template>
  523. <!-- Space separate the compontents of the abstract (dropping the inline markup, sadly) -->
  524. <xsl:template match="abstract" mode="opf.metadata">
  525. <xsl:element name="dc:description">
  526. <xsl:for-each select="formalpara|para|simpara|title">
  527. <xsl:choose>
  528. <xsl:when test="self::formalpara">
  529. <xsl:value-of select="normalize-space(string(title))"/>
  530. <xsl:text>: </xsl:text>
  531. <xsl:value-of select="normalize-space(string(para))"/>
  532. </xsl:when>
  533. <xsl:otherwise>
  534. <xsl:value-of select="normalize-space(string(.))"/>
  535. </xsl:otherwise>
  536. </xsl:choose>
  537. <xsl:if test="self::title">
  538. <xsl:text>:</xsl:text>
  539. </xsl:if>
  540. <xsl:if test="not(position() = last())">
  541. <xsl:text> </xsl:text>
  542. </xsl:if>
  543. </xsl:for-each>
  544. </xsl:element>
  545. </xsl:template>
  546. <xsl:template match="subjectset" mode="opf.metadata">
  547. <xsl:apply-templates select="subject/subjectterm" mode="opf.metadata"/>
  548. </xsl:template>
  549. <xsl:template match="subjectterm" mode="opf.metadata">
  550. <xsl:element name="dc:subject">
  551. <xsl:value-of select="normalize-space(string(.))"/>
  552. </xsl:element>
  553. </xsl:template>
  554. <xsl:template match="publisher" mode="opf.metadata">
  555. <xsl:apply-templates select="publishername" mode="opf.metadata"/>
  556. </xsl:template>
  557. <xsl:template match="publishername" mode="opf.metadata">
  558. <xsl:element name="dc:publisher">
  559. <xsl:value-of select="normalize-space(string(.))"/>
  560. </xsl:element>
  561. </xsl:template>
  562. <xsl:template match="copyright" mode="opf.metadata">
  563. <xsl:variable name="copyright.date">
  564. <xsl:call-template name="copyright.years">
  565. <xsl:with-param name="years" select="year"/>
  566. <xsl:with-param name="print.ranges" select="$make.year.ranges"/>
  567. <xsl:with-param name="single.year.ranges" select="$make.single.year.ranges"/>
  568. </xsl:call-template>
  569. </xsl:variable>
  570. <xsl:if test="not(../date)">
  571. <xsl:element name="dc:date">
  572. <xsl:call-template name="copyright.years">
  573. <xsl:with-param name="years" select="year[last()]"/>
  574. <xsl:with-param name="print.ranges" select="0"/>
  575. <xsl:with-param name="single.year.ranges" select="0"/>
  576. </xsl:call-template>
  577. </xsl:element>
  578. </xsl:if>
  579. <xsl:element name="dc:rights">
  580. <xsl:call-template name="gentext">
  581. <xsl:with-param name="key" select="'Copyright'"/>
  582. </xsl:call-template>
  583. <xsl:call-template name="gentext.space"/>
  584. <xsl:text>&#x00A9;</xsl:text>
  585. <xsl:call-template name="gentext.space"/>
  586. <xsl:value-of select="$copyright.date"/>
  587. <xsl:call-template name="gentext.space"/>
  588. <xsl:apply-templates select="holder" mode="titlepage.mode"/>
  589. </xsl:element>
  590. </xsl:template>
  591. <xsl:template name="opf.guide">
  592. <xsl:if test="contains($toc.params, 'toc') or
  593. /*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]">
  594. <xsl:element namespace="http://www.idpf.org/2007/opf" name="guide">
  595. <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]">
  596. <xsl:element namespace="http://www.idpf.org/2007/opf" name="reference">
  597. <xsl:attribute name="href">
  598. <xsl:value-of select="$epub.cover.html" />
  599. </xsl:attribute>
  600. <xsl:attribute name="type">cover</xsl:attribute>
  601. <xsl:attribute name="title">Cover</xsl:attribute>
  602. </xsl:element>
  603. </xsl:if>
  604. <xsl:if test="contains($toc.params, 'toc')">
  605. <xsl:element namespace="http://www.idpf.org/2007/opf" name="reference">
  606. <xsl:attribute name="href">
  607. <xsl:call-template name="toc-href">
  608. <xsl:with-param name="node" select="/*"/>
  609. </xsl:call-template>
  610. </xsl:attribute>
  611. <xsl:attribute name="type">toc</xsl:attribute>
  612. <xsl:attribute name="title">Table of Contents</xsl:attribute>
  613. </xsl:element>
  614. </xsl:if>
  615. </xsl:element>
  616. </xsl:if>
  617. </xsl:template>
  618. <xsl:template name="opf.spine">
  619. <xsl:element namespace="http://www.idpf.org/2007/opf" name="spine">
  620. <xsl:attribute name="toc">
  621. <xsl:value-of select="$epub.ncx.toc.id"/>
  622. </xsl:attribute>
  623. <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]">
  624. <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
  625. <xsl:attribute name="idref">
  626. <xsl:value-of select="$epub.cover.id"/>
  627. </xsl:attribute>
  628. <xsl:attribute name="linear">
  629. <xsl:choose>
  630. <xsl:when test="$epub.cover.linear">
  631. <xsl:text>yes</xsl:text>
  632. </xsl:when>
  633. <xsl:otherwise>no</xsl:otherwise>
  634. </xsl:choose>
  635. </xsl:attribute>
  636. </xsl:element>
  637. </xsl:if>
  638. <xsl:if test="contains($toc.params, 'toc')">
  639. <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
  640. <xsl:attribute name="idref"> <xsl:value-of select="$epub.html.toc.id"/> </xsl:attribute>
  641. <xsl:attribute name="linear">yes</xsl:attribute>
  642. </xsl:element>
  643. </xsl:if>
  644. <!-- TODO: be nice to have a idref="titlepage" here -->
  645. <xsl:choose>
  646. <xsl:when test="$root.is.a.chunk != '0'">
  647. <xsl:apply-templates select="/*" mode="opf.spine"/>
  648. </xsl:when>
  649. <xsl:otherwise>
  650. <xsl:apply-templates select="/*/*" mode="opf.spine"/>
  651. </xsl:otherwise>
  652. </xsl:choose>
  653. </xsl:element>
  654. </xsl:template>
  655. <xsl:template match="*" mode="opf.spine">
  656. <xsl:variable name="is.chunk">
  657. <xsl:call-template name="chunk">
  658. <xsl:with-param name="node" select="."/>
  659. </xsl:call-template>
  660. </xsl:variable>
  661. <xsl:if test="$is.chunk != 0">
  662. <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
  663. <xsl:attribute name="idref">
  664. <xsl:value-of select="generate-id(.)"/>
  665. </xsl:attribute>
  666. </xsl:element>
  667. <xsl:apply-templates select="*|.//refentry" mode="opf.spine"/>
  668. </xsl:if>
  669. </xsl:template>
  670. <xsl:template name="opf.manifest">
  671. <xsl:element namespace="http://www.idpf.org/2007/opf" name="manifest">
  672. <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
  673. <xsl:attribute name="id"> <xsl:value-of select="$epub.ncx.toc.id"/> </xsl:attribute>
  674. <xsl:attribute name="media-type">application/x-dtbncx+xml</xsl:attribute>
  675. <xsl:attribute name="href"><xsl:value-of select="$epub.ncx.filename"/> </xsl:attribute>
  676. </xsl:element>
  677. <xsl:if test="contains($toc.params, 'toc')">
  678. <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
  679. <xsl:attribute name="id"> <xsl:value-of select="$epub.html.toc.id"/> </xsl:attribute>
  680. <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
  681. <xsl:attribute name="href">
  682. <xsl:call-template name="toc-href">
  683. <xsl:with-param name="node" select="/*"/>
  684. </xsl:call-template>
  685. </xsl:attribute>
  686. </xsl:element>
  687. </xsl:if>
  688. <xsl:if test="$html.stylesheet != ''">
  689. <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
  690. <xsl:attribute name="media-type">text/css</xsl:attribute>
  691. <xsl:attribute name="id">css</xsl:attribute>
  692. <xsl:attribute name="href"><xsl:value-of select="$html.stylesheet"/></xsl:attribute>
  693. </xsl:element>
  694. </xsl:if>
  695. <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]">
  696. <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
  697. <xsl:attribute name="id"> <xsl:value-of select="$epub.cover.id"/> </xsl:attribute>
  698. <xsl:attribute name="href">
  699. <xsl:value-of select="$epub.cover.html"/>
  700. </xsl:attribute>
  701. <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
  702. </xsl:element>
  703. </xsl:if>
  704. <xsl:choose>
  705. <xsl:when test="$epub.embedded.fonts != '' and not(contains($epub.embedded.fonts, ','))">
  706. <xsl:call-template name="embedded-font-item">
  707. <xsl:with-param name="font.file" select="$epub.embedded.fonts"/> <!-- There is just one -->
  708. </xsl:call-template>
  709. </xsl:when>
  710. <xsl:when test="$epub.embedded.fonts != ''">
  711. <xsl:variable name="font.file.tokens" select="str:tokenize($epub.embedded.fonts, ',')"/>
  712. <xsl:for-each select="exsl:node-set($font.file.tokens)">
  713. <xsl:call-template name="embedded-font-item">
  714. <xsl:with-param name="font.file" select="."/>
  715. <xsl:with-param name="font.order" select="position()"/>
  716. </xsl:call-template>
  717. </xsl:for-each>
  718. </xsl:when>
  719. </xsl:choose>
  720. <!-- TODO: be nice to have a id="titlepage" here -->
  721. <xsl:apply-templates select="//part|
  722. //book[*[last()][self::bookinfo]]|
  723. //book[bookinfo]|
  724. //book[*[last()][self::info]]|
  725. //book[info]|
  726. /set|
  727. /set/book|
  728. //reference|
  729. //preface|
  730. //chapter|
  731. //bibliography|
  732. //appendix|
  733. //article|
  734. //glossary|
  735. //section|
  736. //sect1|
  737. //sect2|
  738. //sect3|
  739. //sect4|
  740. //sect5|
  741. //refentry|
  742. //colophon|
  743. //bibliodiv[title]|
  744. //index|
  745. //setindex|
  746. //graphic|
  747. //inlinegraphic|
  748. //mediaobject|
  749. //mediaobjectco|
  750. //inlinemediaobject"
  751. mode="opf.manifest"/>
  752. <xsl:call-template name="opf.calloutlist"/>
  753. </xsl:element>
  754. </xsl:template>
  755. <xsl:template name="opf.calloutlist">
  756. <xsl:variable name="format">
  757. <xsl:call-template name="guess-media-type">
  758. <xsl:with-param name="ext" select="$callout.graphics.extension"/>
  759. </xsl:call-template>
  760. </xsl:variable>
  761. <xsl:if test="(//calloutlist|//co)">
  762. <xsl:call-template name="opf.reference.callout">
  763. <xsl:with-param name="conum" select="1"/>
  764. <xsl:with-param name="format" select="$format"/>
  765. </xsl:call-template>
  766. </xsl:if>
  767. </xsl:template>
  768. <xsl:template name="opf.reference.callout">
  769. <xsl:param name="conum"/>
  770. <xsl:param name="format"/>
  771. <xsl:variable name="filename" select="concat($callout.graphics.path, $conum, $callout.graphics.extension)"/>
  772. <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
  773. <xsl:attribute name="id"> <xsl:value-of select="concat(generate-id(.), 'callout', $conum)"/> </xsl:attribute>
  774. <xsl:attribute name="href"> <xsl:value-of select="$filename"/> </xsl:attribute>
  775. <xsl:attribute name="media-type">
  776. <xsl:value-of select="$format"/>
  777. </xsl:attribute>
  778. </xsl:element>
  779. <xsl:if test="($conum &lt; $callout.graphics.number.limit)">
  780. <xsl:call-template name="opf.reference.callout">
  781. <xsl:with-param name="conum" select="$conum + 1"/>
  782. <xsl:with-param name="format" select="$format"/>
  783. </xsl:call-template>
  784. </xsl:if>
  785. </xsl:template>
  786. <xsl:template name="guess-media-type">
  787. <xsl:param name="ext"></xsl:param>
  788. <xsl:choose>
  789. <xsl:when test="contains($ext, '.gif')">
  790. <xsl:text>image/gif</xsl:text>
  791. </xsl:when>
  792. <xsl:when test="contains($ext, 'GIF')">
  793. <xsl:text>image/gif</xsl:text>
  794. </xsl:when>
  795. <xsl:when test="contains($ext, '.png')">
  796. <xsl:text>image/png</xsl:text>
  797. </xsl:when>
  798. <xsl:when test="contains($ext, 'PNG')">
  799. <xsl:text>image/png</xsl:text>
  800. </xsl:when>
  801. <xsl:when test="contains($ext, '.jpeg')">
  802. <xsl:text>image/jpeg</xsl:text>
  803. </xsl:when>
  804. <xsl:when test="contains($ext, 'JPEG')">
  805. <xsl:text>image/jpeg</xsl:text>
  806. </xsl:when>
  807. <xsl:when test="contains($ext, '.jpg')">
  808. <xsl:text>image/jpeg</xsl:text>
  809. </xsl:when>
  810. <xsl:when test="contains($ext, 'JPG')">
  811. <xsl:text>image/jpeg</xsl:text>
  812. </xsl:when>
  813. <xsl:when test="contains($ext, '.svg')">
  814. <xsl:text>image/svg+xml</xsl:text>
  815. </xsl:when>
  816. <xsl:when test="contains($ext, 'SVG')">
  817. <xsl:text>image/svg+xml</xsl:text>
  818. </xsl:when>
  819. <xsl:otherwise>
  820. <!-- we failed -->
  821. <xsl:text></xsl:text>
  822. </xsl:otherwise>
  823. </xsl:choose>
  824. </xsl:template>
  825. <xsl:template match="mediaobject|
  826. mediaobjectco|
  827. inlinemediaobject"
  828. mode="opf.manifest">
  829. <xsl:variable name="olist" select="imageobject|imageobjectco |videoobject|audioobject |textobject"/>
  830. <xsl:variable name="object.index">
  831. <xsl:call-template name="select.mediaobject.index">
  832. <xsl:with-param name="olist" select="$olist"/>
  833. <xsl:with-param name="count" select="1"/>
  834. </xsl:call-template>
  835. </xsl:variable>
  836. <xsl:variable name="object" select="$olist[position() = $object.index]"/>
  837. <xsl:choose>
  838. <xsl:when test="$object/descendant::imagedata[@format = 'GIF' or
  839. @format = 'GIF87a' or
  840. @format = 'GIF89a' or
  841. @format = 'JPEG' or
  842. @format = 'JPG' or
  843. @format = 'PNG' or
  844. @format = 'SVG']">
  845. <xsl:apply-templates select="$object[descendant::imagedata[@format = 'GIF' or
  846. @format = 'GIF87a' or
  847. @format = 'GIF89a' or
  848. @format = 'JPEG' or
  849. @format = 'JPG' or
  850. @format = 'PNG' or
  851. @format = 'SVG']][1]/imagedata"
  852. mode="opf.manifest"/>
  853. </xsl:when>
  854. <xsl:otherwise>
  855. <xsl:apply-templates select="$object/imagedata[1]"
  856. mode="opf.manifest"/>
  857. </xsl:otherwise>
  858. </xsl:choose>
  859. </xsl:template>
  860. <xsl:template match="cover/mediaobject|
  861. mediaobject[@role='cover']"
  862. mode="opf.manifest">
  863. <xsl:choose>
  864. <xsl:when test="imageobject[@role='front-large']">
  865. <xsl:apply-templates select="imageobject[@role='front-large']/imagedata"
  866. mode="opf.manifest"/>
  867. </xsl:when>
  868. <xsl:otherwise>
  869. <xsl:apply-templates select="imageobject/imagedata[1]"
  870. mode="opf.manifest"/>
  871. </xsl:otherwise>
  872. </xsl:choose>
  873. </xsl:template>
  874. <xsl:template match="mediaobjectco"
  875. mode="opf.manifest">
  876. <xsl:message>WARNING: mediaobjectco almost certainly will not render as expected in .epub!</xsl:message>
  877. <xsl:apply-templates select="imageobjectco/imageobject/imagedata"
  878. mode="opf.manifest"/>
  879. </xsl:template>
  880. <!-- TODO: Barf (xsl:message terminate=yes) if you find a graphic with no reasonable format or a mediaobject w/o same? [option to not die?] -->
  881. <!-- wish I had XSLT2 ...-->
  882. <!-- TODO: priority a hack -->
  883. <xsl:template match="graphic[not(@format)]|
  884. inlinegraphic[not(@format)]|
  885. imagedata[not(@format)]"
  886. mode="opf.manifest">
  887. <xsl:variable name="filename">
  888. <xsl:choose>
  889. <xsl:when test="contains(name(.), 'graphic')">
  890. <xsl:choose>
  891. <xsl:when test="@entityref">
  892. <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  893. </xsl:when>
  894. <xsl:otherwise>
  895. <xsl:apply-templates select="@fileref"/>
  896. </xsl:otherwise>
  897. </xsl:choose>
  898. </xsl:when>
  899. <xsl:otherwise>
  900. <xsl:call-template name="mediaobject.filename">
  901. <xsl:with-param name="object" select=".."/>
  902. </xsl:call-template>
  903. </xsl:otherwise>
  904. </xsl:choose>
  905. </xsl:variable>
  906. <xsl:variable name="format">
  907. <xsl:call-template name="guess-media-type">
  908. <xsl:with-param name="ext" select="@fileref"/>
  909. </xsl:call-template>
  910. </xsl:variable>
  911. <xsl:variable name="fr" select="@fileref"/>
  912. <xsl:if test="$format != ''">
  913. <!-- only do this if we're the first file to match -->
  914. <!-- TODO: Why can't this be simple equality?? (I couldn't get it to work) -->
  915. <xsl:if test="generate-id(.) = generate-id(key('image-filerefs', $fr)[1])">
  916. <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
  917. <xsl:attribute name="id">
  918. <xsl:choose>
  919. <xsl:when test="ancestor::mediaobject[@role='cover'] and parent::*[@role='front-large']">
  920. <xsl:value-of select="$epub.cover.image.id"/>
  921. </xsl:when>
  922. <xsl:when test="ancestor::mediaobject[@role='cover'] and (count(ancestor::mediaobject//imageobject) = 1)">
  923. <xsl:value-of select="$epub.cover.image.id"/>
  924. </xsl:when>
  925. <xsl:when test="ancestor::cover">
  926. <xsl:value-of select="$epub.cover.image.id"/>
  927. </xsl:when>
  928. <xsl:otherwise>
  929. <xsl:value-of select="generate-id(.)"/>
  930. </xsl:otherwise>
  931. </xsl:choose>
  932. </xsl:attribute>
  933. <xsl:attribute name="href"> <xsl:value-of select="$filename"/> </xsl:attribute>
  934. <xsl:attribute name="media-type">
  935. <xsl:value-of select="$format"/>
  936. </xsl:attribute>
  937. </xsl:element>
  938. </xsl:if>
  939. </xsl:if>
  940. </xsl:template>
  941. <!-- Note: Selection of the first interesting imagedata is done in the select -->
  942. <xsl:template match="graphic[@format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or @format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or @format = 'SVG']|
  943. inlinegraphic[@format = 'GIF' or @format = 'GIF87a' or @format = 'GIF89a' or @format = 'JPEG' or @format = 'JPG' or @format = 'PNG' or @format = 'SVG']|
  944. imagedata[@format]"
  945. mode="opf.manifest">
  946. <xsl:variable name="filename">
  947. <xsl:choose>
  948. <xsl:when test="contains(name(.), 'graphic')">
  949. <xsl:choose>
  950. <xsl:when test="@entityref">
  951. <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  952. </xsl:when>
  953. <xsl:otherwise>
  954. <xsl:apply-templates select="@fileref"/>
  955. </xsl:otherwise>
  956. </xsl:choose>
  957. </xsl:when>
  958. <xsl:otherwise>
  959. <xsl:call-template name="mediaobject.filename">
  960. <xsl:with-param name="object" select=".."/>
  961. </xsl:call-template>
  962. </xsl:otherwise>
  963. </xsl:choose>
  964. </xsl:variable>
  965. <xsl:variable name="fr" select="@fileref"/>
  966. <!-- only do this if we're the first file to match -->
  967. <!-- TODO: Why can't this be simple equality?? (I couldn't get it to work) -->
  968. <xsl:if test="generate-id(.) = generate-id(key('image-filerefs', $fr)[1])">
  969. <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
  970. <xsl:attribute name="id">
  971. <xsl:choose>
  972. <xsl:when test="ancestor::mediaobject[@role='cover'] and parent::*[@role='front-large']">
  973. <xsl:value-of select="$epub.cover.image.id"/>
  974. </xsl:when>
  975. <xsl:when test="ancestor::mediaobject[@role='cover'] and (count(ancestor::mediaobject//imageobject) = 1)">
  976. <xsl:value-of select="$epub.cover.image.id"/>
  977. </xsl:when>
  978. <xsl:when test="ancestor::cover">
  979. <xsl:value-of select="$epub.cover.image.id"/>
  980. </xsl:when>
  981. <xsl:otherwise>
  982. <xsl:value-of select="generate-id(.)"/>
  983. </xsl:otherwise>
  984. </xsl:choose>
  985. </xsl:attribute>
  986. <xsl:attribute name="href"> <xsl:value-of select="$filename"/> </xsl:attribute>
  987. <xsl:attribute name="media-type">
  988. <xsl:call-template name="guess-media-type">
  989. <xsl:with-param name="ext" select="@format"/>
  990. </xsl:call-template>
  991. </xsl:attribute>
  992. </xsl:element>
  993. </xsl:if>
  994. </xsl:template>
  995. <!-- Warning: While the test indicate this match list is accurate, it may
  996. need further tweaking to ensure _never_ dropping generated content (XHTML)
  997. from the manifest (OPF file) -->
  998. <xsl:template
  999. match="set|
  1000. book[parent::set]|
  1001. book[*[last()][self::bookinfo]]|
  1002. book[bookinfo]|
  1003. book[*[last()][self::info]]|
  1004. book[info]|
  1005. article|
  1006. part|
  1007. reference|
  1008. preface|
  1009. chapter|
  1010. bibliography|
  1011. appendix|
  1012. glossary|
  1013. section|
  1014. sect1|
  1015. sect2|
  1016. sect3|
  1017. sect4|
  1018. sect5|
  1019. refentry|
  1020. colophon|
  1021. bibliodiv[title]|
  1022. setindex|
  1023. index"
  1024. mode="opf.manifest">
  1025. <xsl:variable name="href">
  1026. <xsl:call-template name="href.target.with.base.dir">
  1027. <xsl:with-param name="context" select="/" />
  1028. <!-- Generate links relative to the location of root file/toc.xml file -->
  1029. </xsl:call-template>
  1030. </xsl:variable>
  1031. <xsl:variable name="id">
  1032. <xsl:value-of select="generate-id(.)"/>
  1033. </xsl:variable>
  1034. <xsl:variable name="is.chunk">
  1035. <xsl:call-template name="chunk">
  1036. <xsl:with-param name="node" select="."/>
  1037. </xsl:call-template>
  1038. </xsl:variable>
  1039. <xsl:if test="$is.chunk != 0">
  1040. <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
  1041. <xsl:attribute name="id"> <xsl:value-of select="$id"/> </xsl:attribute>
  1042. <xsl:attribute name="href"> <xsl:value-of select="$href"/> </xsl:attribute>
  1043. <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
  1044. </xsl:element>
  1045. </xsl:if>
  1046. </xsl:template>
  1047. <xsl:template match="text()" mode="ncx" />
  1048. <xsl:template name="html.head">
  1049. <xsl:param name="prev" select="/foo"/>
  1050. <xsl:param name="next" select="/foo"/>
  1051. <xsl:variable name="this" select="."/>
  1052. <xsl:variable name="home" select="/*[1]"/>
  1053. <xsl:variable name="up" select="parent::*"/>
  1054. <head xmlns="http://www.w3.org/1999/xhtml">
  1055. <xsl:call-template name="system.head.content"/>
  1056. <xsl:call-template name="head.content"/>
  1057. <xsl:call-template name="user.head.content"/>
  1058. </head>
  1059. </xsl:template>
  1060. <!-- OVERRIDES xhtml-1_1/graphics.xsl -->
  1061. <!-- we can't deal with no img/@alt, because it's required. Try grabbing a title before it instead (hopefully meaningful) -->
  1062. <xsl:template name="process.image.attributes">
  1063. <xsl:param name="alt"/>
  1064. <xsl:param name="html.width"/>
  1065. <xsl:param name="html.depth"/>
  1066. <xsl:param name="longdesc"/>
  1067. <xsl:param name="scale"/>
  1068. <xsl:param name="scalefit"/>
  1069. <xsl:param name="scaled.contentdepth"/>
  1070. <xsl:param name="scaled.contentwidth"/>
  1071. <xsl:param name="viewport"/>
  1072. <xsl:choose>
  1073. <xsl:when test="@contentwidth or @contentdepth">
  1074. <!-- ignore @width/@depth, @scale, and @scalefit if specified -->
  1075. <xsl:if test="@contentwidth and $scaled.contentwidth != ''">
  1076. <xsl:attribute name="width">
  1077. <xsl:value-of select="$scaled.contentwidth"/>
  1078. </xsl:attribute>
  1079. </xsl:if>
  1080. <xsl:if test="@contentdepth and $scaled.contentdepth != ''">
  1081. <xsl:attribute name="height">
  1082. <xsl:value-of select="$scaled.contentdepth"/>
  1083. </xsl:attribute>
  1084. </xsl:if>
  1085. </xsl:when>
  1086. <xsl:when test="number($scale) != 1.0">
  1087. <!-- scaling is always uniform, so we only have to specify one dimension -->
  1088. <!-- ignore @scalefit if specified -->
  1089. <xsl:attribute name="width">
  1090. <xsl:value-of select="$scaled.contentwidth"/>
  1091. </xsl:attribute>
  1092. </xsl:when>
  1093. <xsl:when test="$scalefit != 0">
  1094. <xsl:choose>
  1095. <xsl:when test="contains($html.width, '%')">
  1096. <xsl:choose>
  1097. <xsl:when test="$viewport != 0">
  1098. <!-- The *viewport* will be scaled, so use 100% here! -->
  1099. <xsl:attribute name="width">
  1100. <xsl:value-of select="'100%'"/>
  1101. </xsl:attribute>
  1102. </xsl:when>
  1103. <xsl:otherwise>
  1104. <xsl:attribute name="width">
  1105. <xsl:value-of select="$html.width"/>
  1106. </xsl:attribute>
  1107. </xsl:otherwise>
  1108. </xsl:choose>
  1109. </xsl:when>
  1110. <xsl:when test="contains($html.depth, '%')">
  1111. <!-- HTML doesn't deal with this case very well...do nothing -->
  1112. </xsl:when>
  1113. <xsl:when test="$scaled.contentwidth != '' and $html.width != '' and $scaled.contentdepth != '' and $html.depth != ''">
  1114. <!-- scalefit should not be anamorphic; figure out which direction -->
  1115. <!-- has the limiting scale factor and scale in that direction -->
  1116. <xsl:choose>
  1117. <xsl:when test="$html.width div $scaled.contentwidth &gt; $html.depth div $scaled.contentdepth">
  1118. <xsl:attribute name="height">
  1119. <xsl:value-of select="$html.depth"/>
  1120. </xsl:attribute>
  1121. </xsl:when>
  1122. <xsl:otherwise>
  1123. <xsl:attribute name="width">
  1124. <xsl:value-of select="$html.width"/>
  1125. </xsl:attribute>
  1126. </xsl:otherwise>
  1127. </xsl:choose>
  1128. </xsl:when>
  1129. <xsl:when test="$scaled.contentwidth != '' and $html.width != ''">
  1130. <xsl:attribute name="width">
  1131. <xsl:value-of select="$html.width"/>
  1132. </xsl:attribute>
  1133. </xsl:when>
  1134. <xsl:when test="$scaled.contentdepth != '' and $html.depth != ''">
  1135. <xsl:attribute name="height">
  1136. <xsl:value-of select="$html.depth"/>
  1137. </xsl:attribute>
  1138. </xsl:when>
  1139. </xsl:choose>
  1140. </xsl:when>
  1141. </xsl:choose>
  1142. <!-- AN OVERRIDE -->
  1143. <xsl:if test="not(@format ='SVG')">
  1144. <xsl:attribute name="alt">
  1145. <xsl:choose>
  1146. <xsl:when test="$alt != ''">
  1147. <xsl:value-of select="normalize-space($alt)"/>
  1148. </xsl:when>
  1149. <xsl:when test="preceding::title[1]">
  1150. <xsl:value-of select="normalize-space(preceding::title[1])"/>
  1151. </xsl:when>
  1152. <xsl:otherwise>
  1153. <xsl:text>(missing alt)</xsl:text>
  1154. </xsl:otherwise>
  1155. </xsl:choose>
  1156. </xsl:attribute>
  1157. </xsl:if>
  1158. <!-- END OF OVERRIDE -->
  1159. <xsl:if test="$longdesc != ''">
  1160. <xsl:attribute name="longdesc">
  1161. <xsl:value-of select="$longdesc"/>
  1162. </xsl:attribute>
  1163. </xsl:if>
  1164. <xsl:if test="@align and $viewport = 0">
  1165. <xsl:attribute name="style"><xsl:text>text-align: </xsl:text>
  1166. <xsl:choose>
  1167. <xsl:when test="@align = 'center'">middle</xsl:when>
  1168. <xsl:otherwise>
  1169. <xsl:value-of select="@align"/>
  1170. </xsl:otherwise>
  1171. </xsl:choose>
  1172. </xsl:attribute>
  1173. </xsl:if>
  1174. </xsl:template>
  1175. <!-- OVERRIDES xhtml-1_1/chunk-common.xsl -->
  1176. <!-- make a bibliography always a chunk -->
  1177. <xsl:template name="chunk">
  1178. <xsl:param name="node" select="."/>
  1179. <!-- returns 1 if $node is a chunk -->
  1180. <!-- ==================================================================== -->
  1181. <!-- What's a chunk?
  1182. The root element
  1183. appendix
  1184. article
  1185. bibliography ### NO LONGER TRUE in article or part or book
  1186. book
  1187. chapter
  1188. colophon
  1189. glossary in article or part or book
  1190. index in article or part or book
  1191. part
  1192. preface
  1193. refentry
  1194. reference
  1195. sect{1,2,3,4,5} if position()>1 && depth < chunk.section.depth
  1196. section if position()>1 && depth < chunk.section.depth
  1197. set
  1198. setindex
  1199. -->
  1200. <!-- ==================================================================== -->
  1201. <!--
  1202. <xsl:message>
  1203. <xsl:text>chunk: </xsl:text>
  1204. <xsl:value-of select="name($node)"/>
  1205. <xsl:text>(</xsl:text>
  1206. <xsl:value-of select="$node/@id"/>
  1207. <xsl:text>)</xsl:text>
  1208. <xsl:text> csd: </xsl:text>
  1209. <xsl:value-of select="$chunk.section.depth"/>
  1210. <xsl:text> cfs: </xsl:text>
  1211. <xsl:value-of select="$chunk.first.sections"/>
  1212. <xsl:text> ps: </xsl:text>
  1213. <xsl:value-of select="count($node/parent::section)"/>
  1214. <xsl:text> prs: </xsl:text>
  1215. <xsl:value-of select="count($node/preceding-sibling::section)"/>
  1216. </xsl:message>
  1217. -->
  1218. <xsl:choose>
  1219. <xsl:when test="not($node/parent::*)">1</xsl:when>
  1220. <xsl:when test="local-name($node) = 'sect1' and $chunk.section.depth &gt;= 1 and ($chunk.first.sections != 0 or count($node/preceding-sibling::sect1) &gt; 0)">
  1221. <xsl:text>1</xsl:text>
  1222. </xsl:when>
  1223. <xsl:when test="local-name($node) = 'sect2' and $chunk.section.depth &gt;= 2 and ($chunk.first.sections != 0 or count($node/preceding-sibling::sect2) &gt; 0)">
  1224. <xsl:call-template name="chunk">
  1225. <xsl:with-param name="node" select="$node/parent::*"/>
  1226. </xsl:call-template>
  1227. </xsl:when>
  1228. <xsl:when test="local-name($node) = 'sect3' and $chunk.section.depth &gt;= 3 and ($chunk.first.sections != 0 or count($node/preceding-sibling::sect3) &gt; 0)">
  1229. <xsl:call-template name="chunk">
  1230. <xsl:with-param name="node" select="$node/parent::*"/>
  1231. </xsl:call-template>
  1232. </xsl:when>
  1233. <xsl:when test="local-name($node) = 'sect4' and $chunk.section.depth &gt;= 4 and ($chunk.first.sections != 0 or count($node/preceding-sibling::sect4) &gt; 0)">
  1234. <xsl:call-template name="chunk">
  1235. <xsl:with-param name="node" select="$node/parent::*"/>
  1236. </xsl:call-template>
  1237. </xsl:when>
  1238. <xsl:when test="local-name($node) = 'sect5' and $chunk.section.depth &gt;= 5 and ($chunk.first.sections != 0 or count($node/preceding-sibling::sect5) &gt; 0)">
  1239. <xsl:call-template name="chunk">
  1240. <xsl:with-param name="node" select="$node/parent::*"/>
  1241. </xsl:call-template>
  1242. </xsl:when>
  1243. <xsl:when test="local-name($node) = 'section' and $chunk.section.depth &gt;= count($node/ancestor::section)+1 and ($chunk.first.sections != 0 or count($node/preceding-sibling::section) &gt; 0)">
  1244. <xsl:call-template name="chunk">
  1245. <xsl:with-param name="node" select="$node/parent::*"/>
  1246. </xsl:call-template>
  1247. </xsl:when>
  1248. <xsl:when test="local-name($node)='preface'">1</xsl:when>
  1249. <xsl:when test="local-name($node)='chapter'">1</xsl:when>
  1250. <xsl:when test="local-name($node)='appendix'">1</xsl:when>
  1251. <xsl:when test="local-name($node)='article'">1</xsl:when>
  1252. <xsl:when test="local-name($node)='part'">1</xsl:when>
  1253. <xsl:when test="local-name($node)='reference'">1</xsl:when>
  1254. <xsl:when test="local-name($node)='refentry'">1</xsl:when>
  1255. <xsl:when test="local-name($node)='index' and ($generate.index != 0 or count($node/*) &gt; 0) and (local-name($node/parent::*) = 'article' or local-name($node/parent::*) = 'book' or local-name($node/parent::*) = 'part' )">1</xsl:when>
  1256. <!-- AN OVERRIDE -->
  1257. <xsl:when test="local-name($node)='bibliography'">1</xsl:when>
  1258. <!-- END OF OVERRIDE -->
  1259. <xsl:when test="local-name($node)='glossary' and (local-name($node/parent::*) = 'article' or local-name($node/parent::*) = 'book' or local-name($node/parent::*) = 'part' )">1</xsl:when>
  1260. <xsl:when test="local-name($node)='colophon'">1</xsl:when>
  1261. <xsl:when test="local-name($node)='book'">1</xsl:when>
  1262. <xsl:when test="local-name($node)='set'">1</xsl:when>
  1263. <xsl:when test="local-name($node)='setindex'">1</xsl:when>
  1264. <xsl:when test="local-name($node)='legalnotice' and $generate.legalnotice.link != 0">1</xsl:when>
  1265. <xsl:otherwise>0</xsl:otherwise>
  1266. </xsl:choose>
  1267. </xsl:template>
  1268. <!-- OVERRIDES xhtml-1_1/chunk-code.xsl -->
  1269. <!-- Add chunking for bibliography as root element -->
  1270. <!-- AN OVERRIDE -->
  1271. <xsl:template match="set|
  1272. book|
  1273. part|
  1274. preface|
  1275. chapter|
  1276. appendix|
  1277. article|
  1278. reference|
  1279. refentry|
  1280. book/glossary|
  1281. article/glossary|
  1282. part/glossary|
  1283. bibliography|
  1284. colophon"
  1285. priority="1">
  1286. <!-- END OF OVERRIDE -->
  1287. <xsl:choose>
  1288. <xsl:when test="$onechunk != 0 and parent::*">
  1289. <xsl:apply-imports/>
  1290. </xsl:when>
  1291. <xsl:otherwise>
  1292. <xsl:call-template name="process-chunk-element"/>
  1293. </xsl:otherwise>
  1294. </xsl:choose>
  1295. </xsl:template>
  1296. <!-- OVERRIDES xhtml-1_1/graphics.xsl -->
  1297. <!-- Do _NOT_ output any xlink garbage, so if you don't have
  1298. processor with extensions, you're screwed and we're terminating -->
  1299. <xsl:template match="inlinegraphic">
  1300. <xsl:variable name="filename">
  1301. <xsl:choose>
  1302. <xsl:when test="@entityref">
  1303. <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
  1304. </xsl:when>
  1305. <xsl:otherwise>
  1306. <xsl:apply-templates select="@fileref"/>
  1307. </xsl:otherwise>
  1308. </xsl:choose>
  1309. </xsl:variable>
  1310. <xsl:call-template name="anchor"/>
  1311. <xsl:choose>
  1312. <xsl:when test="@format='linespecific'">
  1313. <xsl:choose>
  1314. <xsl:when test="$use.extensions != '0' and $textinsert.extension != '0'">
  1315. <xsl:choose>
  1316. <xsl:when test="element-available('stext:insertfile')">
  1317. <stext:insertfile href="{$filename}" encoding="{$textdata.default.encoding}"/>
  1318. </xsl:when>
  1319. <xsl:when test="element-available('xtext:insertfile')">
  1320. <xtext:insertfile href="{$filename}"/>
  1321. </xsl:when>
  1322. <xsl:otherwise>
  1323. <xsl:message terminate="yes">
  1324. <xsl:text>No insertfile extension available.</xsl:text>
  1325. </xsl:message>
  1326. </xsl:otherwise>
  1327. </xsl:choose>
  1328. </xsl:when>
  1329. <xsl:otherwise>
  1330. <!-- AN OVERRIDE -->
  1331. <xsl:message terminate="yes">
  1332. <xsl:text>No insertfile extension available. Use a different processor (with extensions) or turn on $use.extensions and $textinsert.extension (see docs for more). </xsl:text>
  1333. </xsl:message>
  1334. <!-- END OF OVERRIDE -->
  1335. </xsl:otherwise>
  1336. </xsl:choose>
  1337. </xsl:when>
  1338. <xsl:otherwise>
  1339. <xsl:call-template name="process.image"/>
  1340. </xsl:otherwise>
  1341. </xsl:choose>
  1342. </xsl:template>
  1343. <xsl:template name="cover">
  1344. <xsl:apply-templates select="/*/*[contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]"/>
  1345. </xsl:template>
  1346. <xsl:template match="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]">
  1347. <xsl:call-template name="write.chunk">
  1348. <xsl:with-param name="filename">
  1349. <xsl:value-of select="$epub.cover.filename" />
  1350. </xsl:with-param>
  1351. <xsl:with-param name="method" select="'xml'" />
  1352. <xsl:with-param name="encoding" select="'utf-8'" />
  1353. <xsl:with-param name="indent" select="'no'" />
  1354. <xsl:with-param name="quiet" select="$chunk.quietly" />
  1355. <xsl:with-param name="content">
  1356. <xsl:element namespace="http://www.w3.org/1999/xhtml" name="html">
  1357. <xsl:element namespace="http://www.w3.org/1999/xhtml" name="head">
  1358. <xsl:element namespace="http://www.w3.org/1999/xhtml" name="title">Cover</xsl:element>
  1359. <xsl:element namespace="http://www.w3.org/1999/xhtml" name="style">
  1360. <xsl:attribute name="type">text/css</xsl:attribute>
  1361. <!-- Help the cover image scale nicely in the CSS then apply a max-width to look better in Adobe Digital Editions -->
  1362. <xsl:text> img { max-width: 100%; }</xsl:text>
  1363. </xsl:element>
  1364. </xsl:element>
  1365. <xsl:element namespace="http://www.w3.org/1999/xhtml" name="body">
  1366. <xsl:element namespace="http://www.w3.org/1999/xhtml" name="div">
  1367. <xsl:attribute name="id">
  1368. <xsl:value-of select="$epub.cover.image.id"/>
  1369. </xsl:attribute>
  1370. <xsl:choose>
  1371. <xsl:when test="imageobject[@role='front-large']">
  1372. <xsl:apply-templates select="imageobject[@role='front-large']"/>
  1373. </xsl:when>
  1374. <xsl:otherwise>
  1375. <xsl:apply-templates select="imageobject[1]"/>
  1376. </xsl:otherwise>
  1377. </xsl:choose>
  1378. </xsl:element>
  1379. <!-- If this is defined as an explicit cover page, then process
  1380. any remaining text -->
  1381. <xsl:if test="ancestor::cover">
  1382. <xsl:apply-templates select="ancestor::cover/para"/>
  1383. </xsl:if>
  1384. </xsl:element>
  1385. </xsl:element>
  1386. </xsl:with-param>
  1387. </xsl:call-template>
  1388. </xsl:template>
  1389. <xsl:template name="cover-svg">
  1390. <xsl:param name="node"/>
  1391. </xsl:template>
  1392. <xsl:template name="toc-href">
  1393. <xsl:param name="node" select="."/>
  1394. <xsl:apply-templates select="$node" mode="recursive-chunk-filename">
  1395. <xsl:with-param name="recursive" select="true()"/>
  1396. </xsl:apply-templates>
  1397. <xsl:text>-toc</xsl:text>
  1398. <xsl:value-of select="$html.ext"/>
  1399. </xsl:template>
  1400. <xsl:template match="bibliodiv[title]" mode="label.markup">
  1401. </xsl:template>
  1402. <xsl:template match="token" mode="opf.manifest.font">
  1403. <xsl:call-template name="embedded-font-item">
  1404. <xsl:with-param name="font.file" select="."/>
  1405. </xsl:call-template>
  1406. </xsl:template>
  1407. <xsl:template name="embedded-font-item">
  1408. <xsl:param name="font.file"/>
  1409. <xsl:param name="font.order" select="1"/>
  1410. <xsl:element namespace="http://www.idpf.org/2007/opf" name="item">
  1411. <xsl:attribute name="id">
  1412. <xsl:value-of select="concat('epub.embedded.font.', $font.order)"/>
  1413. </xsl:attribute>
  1414. <xsl:attribute name="href"><xsl:value-of select="$font.file"/></xsl:attribute>
  1415. <xsl:choose>
  1416. <xsl:when test="contains($font.file, 'otf')">
  1417. <xsl:attribute name="media-type">font/opentype</xsl:attribute>
  1418. </xsl:when>
  1419. <xsl:otherwise>
  1420. <xsl:message>
  1421. <xsl:text>WARNING: OpenType fonts should be supplied! (</xsl:text>
  1422. <xsl:value-of select="$font.file"/>
  1423. <xsl:text>)</xsl:text>
  1424. </xsl:message>
  1425. </xsl:otherwise>
  1426. </xsl:choose>
  1427. </xsl:element>
  1428. </xsl:template>
  1429. <!-- Change section.heading to improve SEO on generated HTML by doing heading levels
  1430. "correctly". SEO rules are sometimes silly silly, but this does actually create
  1431. a semantic improvement.
  1432. Note: This template needs to be manually maintained outside of the html/sections.xsl
  1433. code, so make sure important changes get reintegrated. -->
  1434. <xsl:template name="section.heading">
  1435. <xsl:param name="section" select="."/>
  1436. <xsl:param name="level" select="1"/>
  1437. <xsl:param name="allow-anchors" select="1"/>
  1438. <xsl:param name="title"/>
  1439. <xsl:param name="class" select="'title'"/>
  1440. <xsl:variable name="id">
  1441. <xsl:choose>
  1442. <!-- Make sure the subtitle doesn't get the same id as the title -->
  1443. <xsl:when test="self::subtitle">
  1444. <xsl:call-template name="object.id">
  1445. <xsl:with-param name="object" select="."/>
  1446. </xsl:call-template>
  1447. </xsl:when>
  1448. <!-- if title is in an *info wrapper, get the grandparent -->
  1449. <xsl:when test="contains(local-name(..), 'info')">
  1450. <xsl:call-template name="object.id">
  1451. <xsl:with-param name="object" select="../.."/>
  1452. </xsl:call-template>
  1453. </xsl:when>
  1454. <xsl:otherwise>
  1455. <xsl:call-template name="object.id">
  1456. <xsl:with-param name="object" select=".."/>
  1457. </xsl:call-template>
  1458. </xsl:otherwise>
  1459. </xsl:choose>
  1460. </xsl:variable>
  1461. <!-- For SEO, we try to actually ensure we *always* output one and only one h1,
  1462. so unlike the regular stylesheets, we don't add one to the section level and
  1463. we get the right behavior because of chunking. -->
  1464. <xsl:variable name="hlevel">
  1465. <xsl:choose>
  1466. <!-- highest valid HTML H level is H6; so anything nested deeper
  1467. than 7 levels down just becomes H6 -->
  1468. <xsl:when test="$level &gt; 6">6</xsl:when>
  1469. <xsl:otherwise>
  1470. <xsl:value-of select="$level"/>
  1471. </xsl:otherwise>
  1472. </xsl:choose>
  1473. </xsl:variable>
  1474. <xsl:element name="h{$hlevel}" namespace="http://www.w3.org/1999/xhtml">
  1475. <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
  1476. <xsl:if test="$css.decoration != '0'">
  1477. <xsl:if test="$hlevel&lt;3">
  1478. <xsl:attribute name="style">clear: both</xsl:attribute>
  1479. </xsl:if>
  1480. </xsl:if>
  1481. <xsl:if test="$allow-anchors != 0 and $generate.id.attributes = 0">
  1482. <xsl:call-template name="anchor">
  1483. <xsl:with-param name="node" select="$section"/>
  1484. <xsl:with-param name="conditional" select="0"/>
  1485. </xsl:call-template>
  1486. </xsl:if>
  1487. <xsl:if test="$generate.id.attributes != 0 and not(local-name(.) = 'appendix')">
  1488. <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
  1489. </xsl:if>
  1490. <xsl:copy-of select="$title"/>
  1491. </xsl:element>
  1492. </xsl:template>
  1493. <!-- ==================================================================== -->
  1494. <xsl:template match="bridgehead">
  1495. <xsl:variable name="container" select="(ancestor::appendix |ancestor::article |ancestor::bibliography |ancestor::chapter |ancestor::glossary |ancestor::glossdiv |ancestor::index |ancestor::partintro |ancestor::preface |ancestor::refsect1 |ancestor::refsect2 |ancestor::refsect3 |ancestor::sect1 |ancestor::sect2 |ancestor::sect3 |ancestor::sect4 |ancestor::sect5 |ancestor::section |ancestor::setindex |ancestor::simplesect)[last()]"/>
  1496. <xsl:variable name="clevel">
  1497. <xsl:choose>
  1498. <xsl:when test="local-name($container) = 'appendix' or local-name($container) = 'chapter' or local-name($container) = 'article' or local-name($container) = 'bibliography' or local-name($container) = 'glossary' or local-name($container) = 'index' or local-name($container) = 'partintro' or local-name($container) = 'preface' or local-name($container) = 'setindex'">1</xsl:when>
  1499. <xsl:when test="local-name($container) = 'glossdiv'">
  1500. <xsl:value-of select="count(ancestor::glossdiv)+1"/>
  1501. </xsl:when>
  1502. <xsl:when test="local-name($container) = 'sect1' or local-name($container) = 'sect2' or local-name($container) = 'sect3' or local-name($container) = 'sect4' or local-name($container) = 'sect5' or local-name($container) = 'refsect1' or local-name($container) = 'refsect2' or local-name($container) = 'refsect3' or local-name($container) = 'section' or local-name($container) = 'simplesect'">
  1503. <xsl:variable name="slevel">
  1504. <xsl:call-template name="section.level">
  1505. <xsl:with-param name="node" select="$container"/>
  1506. </xsl:call-template>
  1507. </xsl:variable>
  1508. <xsl:value-of select="$slevel + 1"/>
  1509. </xsl:when>
  1510. <xsl:otherwise>1</xsl:otherwise>
  1511. </xsl:choose>
  1512. </xsl:variable>
  1513. <!-- HTML H level is one higher than section level -->
  1514. <xsl:variable name="hlevel">
  1515. <xsl:choose>
  1516. <xsl:when test="@renderas = 'sect1'">1</xsl:when>
  1517. <xsl:when test="@renderas = 'sect2'">2</xsl:when>
  1518. <xsl:when test="@renderas = 'sect3'">3</xsl:when>
  1519. <xsl:when test="@renderas = 'sect4'">4</xsl:when>
  1520. <xsl:when test="@renderas = 'sect5'">5</xsl:when>
  1521. <xsl:otherwise>
  1522. <xsl:value-of select="$clevel + 1"/>
  1523. </xsl:otherwise>
  1524. </xsl:choose>
  1525. </xsl:variable>
  1526. <xsl:element name="h{$hlevel}" namespace="http://www.w3.org/1999/xhtml">
  1527. <xsl:call-template name="anchor">
  1528. <xsl:with-param name="conditional" select="0"/>
  1529. </xsl:call-template>
  1530. <xsl:apply-templates/>
  1531. </xsl:element>
  1532. </xsl:template>
  1533. <!-- SEO customization #2 -->
  1534. <xsl:template name="component.title">
  1535. <xsl:param name="node" select="."/>
  1536. <xsl:variable name="level">
  1537. <xsl:choose>
  1538. <xsl:when test="ancestor::section">
  1539. <xsl:value-of select="count(ancestor::section)+1"/>
  1540. </xsl:when>
  1541. <xsl:when test="ancestor::sect5">6</xsl:when>
  1542. <xsl:when test="ancestor::sect4">5</xsl:when>
  1543. <xsl:when test="ancestor::sect3">4</xsl:when>
  1544. <xsl:when test="ancestor::sect2">3</xsl:when>
  1545. <xsl:when test="ancestor::sect1">2</xsl:when>
  1546. <xsl:otherwise>1</xsl:otherwise>
  1547. </xsl:choose>
  1548. </xsl:variable>
  1549. <xsl:element name="h{$level}" namespace="http://www.w3.org/1999/xhtml">
  1550. <xsl:attribute name="class">title</xsl:attribute>
  1551. <xsl:if test="$generate.id.attributes = 0">
  1552. <xsl:call-template name="anchor">
  1553. <xsl:with-param name="node" select="$node"/>
  1554. <xsl:with-param name="conditional" select="0"/>
  1555. </xsl:call-template>
  1556. </xsl:if>
  1557. <xsl:apply-templates select="$node" mode="object.title.markup">
  1558. <xsl:with-param name="allow-anchors" select="1"/>
  1559. </xsl:apply-templates>
  1560. </xsl:element>
  1561. </xsl:template>
  1562. </xsl:stylesheet>