1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506 |
- <?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE xsl:stylesheet [
- <!ENTITY uppercase "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'">
- <!ENTITY lowercase "'abcdefghijklmnopqrstuvwxyz'">
- ]>
- <xsl:stylesheet
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:exsl="http://exslt.org/common"
- xmlns:set="http://exslt.org/sets"
- xmlns="http://www.w3.org/1999/xhtml"
- xmlns:epub="http://www.idpf.org/2007/ops"
- xmlns:m="http://www.w3.org/1998/Math/MathML"
- xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon"
- xmlns:ssml="http://www.w3.org/2001/10/synthesis"
- xmlns:svg="http://www.w3.org/2000/svg"
- xmlns:opf="http://www.idpf.org/2007/opf"
- xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns:cf="http://docbook.sourceforge.net/xmlns/chunkfast/1.0"
- xmlns:date="http://exslt.org/dates-and-times"
- xmlns:dcterms="http://purl.org/dc/terms/"
- xmlns:ncx="http://www.daisy.org/z3986/2005/ncx/"
- xmlns:db="http://docbook.org/ns/docbook"
- xmlns:stext="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.TextFactory"
- xmlns:str="http://exslt.org/strings"
- xmlns:xtext="xalan://com.nwalsh.xalan.Text"
- extension-element-prefixes="stext xtext"
- exclude-result-prefixes="#default cf date db dc dcterms epub exsl m ncx opf pls set ssml stext str svg xtext"
- version="1.0">
- <!-- $Id: epub3-element-mods.xsl,v 1.1 2011-09-16 21:43:45 bobs Exp $ -->
- <xsl:import href="titlepage.templates.xsl"/>
- <!--
- <xsl:key name="image-filerefs" match="graphic|inlinegraphic|imagedata" use="@fileref"/>
- -->
- <!--==============================================================-->
- <!-- DocBook XSL Parameter settings -->
- <!--==============================================================-->
- <!-- separate file for toc -->
- <xsl:param name="chunk.tocs.and.lots" select="1"/>
- <xsl:param name="toc.section.depth" select="2"/>
- <xsl:param name="generate.toc">
- book toc,title,figure,table,example,equation
- article toc,title,figure,table,example,equation
- </xsl:param>
- <xsl:param name="generate.manifest" select="0"/>
- <xsl:param name="manifest.in.base.dir" select="1"/>
- <xsl:param name="base.dir" select="'OEBPS/'"/>
- <xsl:param name="index.links.to.section" select="0"/>
- <!-- Epub does not yet support external links -->
- <xsl:param name="activate.external.olinks" select="0"/>
- <!-- Turning this on crashes ADE, which is unbelievably awesome -->
- <xsl:param name="formal.object.break.after">0</xsl:param>
- <xsl:param name="callout.graphics" select="1"/>
- <xsl:param name="callout.graphics.extension">.png</xsl:param>
- <xsl:param name="callout.graphics.number.limit" select="15"/>
- <xsl:param name="callout.graphics.path" select="'images/callouts/'"/>
- <xsl:param name="show.comments" select="0"/>
- <!-- no navigation in .epub -->
- <xsl:param name="suppress.navigation" select="'1'"/>
- <!-- EPUB3: use ol lists in table of contents -->
- <xsl:param name="toc.list.type">ol</xsl:param>
- <xsl:param name="autotoc.label.in.hyperlink" select="1"/>
- <xsl:param name="css.decoration" select="1"/>
- <!-- generate the css file from a source file -->
- <xsl:param name="make.clean.html" select="1"/>
- <!-- specify the default epub3 stylesheet -->
- <xsl:param name="docbook.css.source">docbook-epub.css.xml</xsl:param>
- <!-- for custom CSS, use the custom.css.source param -->
- <xsl:param name="custom.css.source"></xsl:param>
- <!--==============================================================-->
- <!-- New EPUB3 Parameters -->
- <!--==============================================================-->
- <xsl:param name="epub.version">3.0</xsl:param>
- <!-- optional ncx for backwards compatibility -->
- <xsl:param name="epub.include.ncx" select="1"/>
- <xsl:param name="epub.ncx.depth">4</xsl:param> <!-- Not functional until http://code.google.com/p/epubcheck/issues/detail?id=70 is resolved -->
- <!-- currently optional duplicate dcterms properties, may be required in future -->
- <xsl:param name="epub.include.metadata.dcterms" select="1"/>
- <!-- optional guide element for backwards compatibility -->
- <xsl:param name="epub.include.guide" select="1"/>
- <!-- some dc: currently required, to be replaced in future version -->
- <xsl:param name="epub.include.metadata.dc.elements" select="1"/>
- <!-- Some dc: elements will remain optional according to the spec -->
- <xsl:param name="epub.include.optional.metadata.dc.elements" select="1"/>
- <xsl:param name="epub.autolabel" select="0"/>
- <xsl:param
- name="epub.vocabulary.profile.content">http://www.idpf.org/epub/30/profile/content/</xsl:param>
- <xsl:param
- name="epub.vocabulary.profile.package">http://www.idpf.org/epub/30/profile/package/</xsl:param>
- <xsl:param name="epub.output.epub.types" select="1"/>
- <xsl:param name="epub.oebps.dir" select="'OEBPS'"/>
- <xsl:param name="epub.metainf.dir" select="'META-INF/'"/>
- <xsl:param name="epub.ncx.filename" select="'toc.ncx'"/>
- <xsl:param name="epub.mimetype.filename" select="'mimetype'"/>
- <xsl:param name="epub.mimetype.value" select="'application/epub+zip'"/>
- <xsl:param name="epub.container.filename" select="'container.xml'"/>
- <xsl:param name="epub.package.filename" select="'package.opf'"/>
- <xsl:param name="epub.cover.filename" select="concat('cover', $html.ext)"/>
- <xsl:param name="epub.cover.linear" select="0" />
- <!-- names of id attributes used in package files -->
- <xsl:param name="epub.meta.identifier.id">meta-identifier</xsl:param>
- <xsl:param name="epub.dc.identifier.id">pub-identifier</xsl:param>
- <xsl:param name="epub.meta.title.id">meta-title</xsl:param>
- <xsl:param name="epub.dc.title.id">pub-title</xsl:param>
- <xsl:param name="epub.meta.language.id">meta-language</xsl:param>
- <xsl:param name="epub.dc.language.id">pub-language</xsl:param>
- <xsl:param name="epub.meta.creator.id">meta-creator</xsl:param>
- <xsl:param name="epub.dc.creator.id">pub-creator</xsl:param>
- <xsl:param name="epub.ncx.toc.id">ncxtoc</xsl:param>
- <xsl:param name="epub.ncx.manifest.id">ncx</xsl:param>
- <xsl:param name="epub.ncx.mediatype">application/x-dtbncx+xml</xsl:param>
- <xsl:param name="epub.xhtml.mediatype">application/xhtml+xml</xsl:param>
- <xsl:param name="epub.html.toc.id">htmltoc</xsl:param>
- <xsl:param name="epub.cover.filename.id" select="'cover'"/>
- <xsl:param name="epub.cover.image.id" select="'cover-image'"/>
- <xsl:param name="epub.embedded.fonts"></xsl:param>
- <xsl:param name="epub.namespace">http://www.idpf.org/2007/ops</xsl:param>
- <xsl:param name="opf.namespace">http://www.idpf.org/2007/opf</xsl:param>
- <xsl:param name="ncx.namespace">http://www.daisy.org/z3986/2005/ncx/</xsl:param>
- <xsl:param name="dc.namespace">http://purl.org/dc/elements/1.1/</xsl:param>
- <!-- prefix generated ids in package elements so they differ from content ids -->
- <xsl:param name="epub.package.id.prefix">id-</xsl:param>
- <!-- editor is either a creator or contributor -->
- <xsl:param name="editor.property">contributor</xsl:param>
- <!-- Generate full output path -->
- <xsl:param name="epub.package.dir" select="concat($chunk.base.dir, '../')"/>
- <xsl:param name="epub.ncx.pathname"
- select="concat($chunk.base.dir, $epub.ncx.filename)"/>
- <xsl:param name="epub.container.pathname"
- select="concat($epub.package.dir, $epub.metainf.dir,
- $epub.container.filename)"/>
- <xsl:param name="epub.package.pathname"
- select="concat($chunk.base.dir, $epub.package.filename)"/>
- <xsl:param name="epub.cover.pathname"
- select="concat($chunk.base.dir, $epub.cover.filename)"/>
- <xsl:param name="epub.mimetype.pathname"
- select="concat($epub.package.dir, $epub.mimetype.filename)"/>
- <xsl:param name="kindle.extensions" select="0"/>
- <!--==============================================================-->
- <!-- Internal variables used for computing certain metadata -->
- <!--==============================================================-->
- <xsl:variable name="epub3.chunk.hierarchy">
- <xsl:apply-templates select="/*" mode="find.chunks"/>
- </xsl:variable>
- <xsl:variable name="chunkset" select="exsl:node-set($epub3.chunk.hierarchy)//cf:div"/>
- <!--==============================================================-->
- <!-- Template customizations -->
- <!--==============================================================-->
- <!-- This is used only by ncx piece -->
- <xsl:variable name="root.is.a.chunk">
- <xsl:choose>
- <xsl:when test="/*[not(self::book)][not(sect1) or not(section)]">
- <xsl:text>1</xsl:text>
- </xsl:when>
- <xsl:when test="/book[*[last()][self::bookinfo]]|book[bookinfo]">
- <xsl:text>1</xsl:text>
- </xsl:when>
- <xsl:when test="/book[*[last()][self::info]]|book[info]">
- <xsl:text>1</xsl:text>
- </xsl:when>
- <xsl:when test="/bibliography">
- <xsl:text>1</xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>0</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <!-- EPUB3: Add generation of epub publication files -->
- <xsl:template match="*" mode="process.root">
- <xsl:variable name="doc" select="self::*"/>
- <xsl:call-template name="user.preroot"/>
- <xsl:call-template name="root.messages"/>
- <html>
- <head>
- <xsl:call-template name="system.head.content">
- <xsl:with-param name="node" select="$doc"/>
- </xsl:call-template>
- <xsl:call-template name="head.content">
- <xsl:with-param name="node" select="$doc"/>
- </xsl:call-template>
- <xsl:call-template name="user.head.content">
- <xsl:with-param name="node" select="$doc"/>
- </xsl:call-template>
- </head>
- <body>
- <xsl:call-template name="body.attributes"/>
- <xsl:call-template name="user.header.content">
- <xsl:with-param name="node" select="$doc"/>
- </xsl:call-template>
- <xsl:apply-templates select="."/>
- <xsl:call-template name="user.footer.content">
- <xsl:with-param name="node" select="$doc"/>
- </xsl:call-template>
- </body>
- </html>
- <xsl:value-of select="$html.append"/>
-
- <!-- Generate any css files only once, not once per chunk -->
- <xsl:call-template name="generate.css.files"/>
- <xsl:call-template name="generate.epub.files"/>
- </xsl:template>
- <xsl:template name="generate.epub.files">
- <!-- Generate epub3 files -->
- <xsl:message>
- <xsl:text>Generating EPUB package files.</xsl:text>
- </xsl:message>
- <xsl:apply-templates select="." mode="opf"/>
- <xsl:apply-templates select="." mode="container"/>
- <xsl:call-template name="mimetype"/>
- <xsl:if test="$epub.include.ncx != 0">
- <xsl:call-template name="ncx"/>
- </xsl:if>
- </xsl:template>
- <!-- Generate the package file -->
- <xsl:template match="*" mode="opf">
- <xsl:variable name="lang">
- <xsl:call-template name="l10n.language"/>
- </xsl:variable>
- <xsl:variable name="content">
- <!-- use xsl:element so output does not have a namespace prefix -->
- <xsl:element name="package" namespace="{$opf.namespace}">
- <!-- Add the package namespaces at the top -->
- <xsl:call-template name="add.package.namespaces"/>
- <xsl:attribute name="version">
- <xsl:value-of select="$epub.version"/>
- </xsl:attribute>
- <xsl:attribute name="xml:lang">
- <xsl:value-of select="$lang"/>
- </xsl:attribute>
- <!-- No profile att in 2011-09-06 spec
- <xsl:attribute name="profile">
- <xsl:value-of select="$epub.vocabulary.profile.package"/>
- </xsl:attribute>
- -->
- <xsl:attribute name="unique-identifier">
- <xsl:value-of select="$epub.dc.identifier.id"/>
- </xsl:attribute>
- <xsl:call-template name="package.metadata"/>
- <xsl:call-template name="package.manifest"/>
- <xsl:call-template name="package.spine"/>
- <xsl:if test="$epub.include.guide != 0">
- <xsl:call-template name="package.guide"/>
- </xsl:if>
- </xsl:element>
- </xsl:variable>
- <xsl:call-template name="write.chunk">
- <xsl:with-param name="filename">
- <xsl:value-of select="$epub.package.pathname" />
- </xsl:with-param>
- <xsl:with-param name="content" select="$content"/>
- <xsl:with-param name="method" select="'xml'" />
- <xsl:with-param name="encoding" select="'utf-8'" />
- <xsl:with-param name="indent" select="'yes'" />
- <xsl:with-param name="quiet" select="$chunk.quietly" />
- <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
- <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
- </xsl:call-template>
- </xsl:template>
- <xsl:template name="package.metadata">
- <xsl:element name="metadata" namespace="{$opf.namespace}">
- <xsl:call-template name="metadata.identifier"/>
- <xsl:call-template name="metadata.title"/>
- <xsl:call-template name="metadata.language"/>
- <xsl:call-template name="metadata.modified"/>
- <xsl:call-template name="metadata.cover"/>
- <xsl:call-template name="metadata.other.info"/>
-
- </xsl:element>
- </xsl:template>
- <xsl:template name="doc.title">
- <xsl:apply-templates select="." mode="title.markup"/>
- </xsl:template>
- <xsl:template name="metadata.identifier">
- <xsl:variable name="package.id.value">
- <xsl:call-template name="package-identifier"/>
- </xsl:variable>
- <xsl:if test="$epub.include.metadata.dc.elements != 0">
- <!-- dc:identifier element -->
- <dc:identifier>
- <xsl:attribute name="id">
- <xsl:value-of select="$epub.dc.identifier.id"/>
- </xsl:attribute>
- <!--
- <xsl:attribute name="prefer">
- <xsl:value-of select="$epub.meta.identifier.id"/>
- </xsl:attribute>
- -->
- <xsl:copy-of select="$package.id.value"/>
- </dc:identifier>
- </xsl:if>
- <xsl:if test="$epub.include.metadata.dcterms != 0">
- <!-- equivalent meta identifier element -->
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="id">
- <xsl:value-of select="$epub.meta.identifier.id"/>
- </xsl:attribute>
- <xsl:attribute name="property">dcterms:identifier</xsl:attribute>
- <xsl:copy-of select="$package.id.value"/>
- </xsl:element>
- </xsl:if>
- </xsl:template>
- <xsl:template name="metadata.title">
- <xsl:variable name="doc.title">
- <xsl:call-template name="doc.title"/>
- </xsl:variable>
- <xsl:if test="$epub.include.metadata.dc.elements != 0">
- <dc:title>
- <xsl:attribute name="id">
- <xsl:value-of select="$epub.dc.title.id"/>
- </xsl:attribute>
- <!--
- <xsl:attribute name="prefer">
- <xsl:value-of select="$epub.meta.title.id"/>
- </xsl:attribute>
- -->
- <xsl:value-of select="normalize-space($doc.title)"/>
- </dc:title>
- </xsl:if>
- <xsl:if test="$epub.include.metadata.dcterms != 0">
- <!-- equivalent meta title element -->
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="property">dcterms:title</xsl:attribute>
- <xsl:attribute name="id">
- <xsl:value-of select="$epub.meta.title.id"/>
- </xsl:attribute>
- <xsl:value-of select="normalize-space($doc.title)"/>
- </xsl:element>
- </xsl:if>
- </xsl:template>
- <xsl:template name="metadata.language">
- <xsl:variable name="lang">
- <xsl:call-template name="l10n.language"/>
- </xsl:variable>
- <xsl:if test="$epub.include.metadata.dc.elements != 0">
- <dc:language>
- <xsl:if test="$kindle.extensions = 0">
- <xsl:attribute name="id">
- <xsl:value-of select="$epub.dc.language.id"/>
- </xsl:attribute>
- </xsl:if>
- <xsl:value-of select="$lang"/>
- </dc:language>
- </xsl:if>
- <xsl:if test="$epub.include.metadata.dcterms != 0">
- <!-- equivalent meta lang element -->
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="property">dcterms:language</xsl:attribute>
- <xsl:attribute name="id">
- <xsl:value-of select="$epub.meta.language.id"/>
- </xsl:attribute>
- <xsl:value-of select="$lang"/>
- </xsl:element>
- </xsl:if>
- </xsl:template>
-
- <xsl:template name="metadata.modified">
- <xsl:variable name="local.datetime" select="date:date-time()"/>
- <xsl:variable name="utc.datetime">
- <xsl:call-template name="convert.date.to.utc">
- <xsl:with-param name="date" select="$local.datetime"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="string-length($utc.datetime) != 0">
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="property">dcterms:modified</xsl:attribute>
- <xsl:value-of select="$utc.datetime"/>
- </xsl:element>
- <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>
- </xsl:when>
- <xsl:otherwise>
- <xsl:message terminate="yes">
- <xsl:text>ERROR: no last-modified date value could be determined, </xsl:text>
- <xsl:text>so cannot output required meta element with </xsl:text>
- <xsl:text>dcterms:modified attribute. Exiting.</xsl:text>
- </xsl:message>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template name="convert.date.to.utc">
- <xsl:param name="date" select="''"/>
- <!-- input format is YYYY-MM-DDTHH:MM:SS-X:00
- where -X:00 is the offset from UTC. -->
- <!-- output format is YYYY-MM-DDTHH:MM:SSZ with no offset -->
- <!-- FIX ME: Not so easy without a proper UTC date function. -->
- <!-- Currently it just converts the local time to this format, which is
- not the correct UTC time. -->
- <xsl:value-of select="concat(substring($date,1,19), 'Z')"/>
- </xsl:template>
- <!-- This cover meta element used by kindlegen, at least -->
- <xsl:template name="metadata.cover">
- <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
- <xsl:variable name="cover.image"
- select="$info//mediaobject[@role='cover' or ancestor::cover]"/>
- <xsl:if test="$cover.image">
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="content">
- <xsl:value-of select="$epub.cover.image.id"/>
- </xsl:attribute>
- <xsl:attribute name="name">cover</xsl:attribute>
- </xsl:element>
- </xsl:if>
- </xsl:template>
- <xsl:template name="metadata.other.info">
- <!-- Take info relative to selected root element -->
- <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
- <xsl:apply-templates select="$info/*" mode="opf.metadata"/>
- </xsl:template>
- <xsl:template match="*" mode="opf.metadata">
- <!-- default is no output -->
- </xsl:template>
- <xsl:template match="authorgroup" mode="opf.metadata">
- <xsl:apply-templates select="*" mode="opf.metadata"/>
- </xsl:template>
- <xsl:template match="author|corpauthor" mode="opf.metadata">
- <xsl:variable name="n">
- <xsl:choose>
- <xsl:when test="self::corpauthor">
- <xsl:apply-templates/>
- </xsl:when>
- <xsl:when test="org/orgname">
- <xsl:apply-templates select="org/orgname"/>
- </xsl:when>
- <xsl:when test="orgname">
- <xsl:apply-templates select="orgname"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:call-template name="person.name">
- <xsl:with-param name="node" select="."/>
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:if test="string-length($n) != 0">
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="id">
- <xsl:value-of select="concat($epub.meta.creator.id, position())"/>
- </xsl:attribute>
- <xsl:attribute name="property">dcterms:creator</xsl:attribute>
- <xsl:value-of select="normalize-space(string($n))"/>
- </xsl:element>
- <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
- <dc:creator>
- <xsl:attribute name="id">
- <xsl:value-of select="concat($epub.dc.creator.id, position())"/>
- </xsl:attribute>
- <xsl:value-of select="$n"/>
- </dc:creator>
- </xsl:if>
- </xsl:if>
- </xsl:template>
- <xsl:template match="editor" mode="opf.metadata">
- <xsl:variable name="n">
- <xsl:choose>
- <xsl:when test="orgname">
- <xsl:apply-templates select="orgname"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:call-template name="person.name">
- <xsl:with-param name="node" select="."/>
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:variable name="name">
- <xsl:choose>
- <xsl:when test="string-length($editor.property) != 0">
- <xsl:value-of select="$editor.property"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>contributor</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="property">
- <xsl:text>dcterms:</xsl:text>
- <xsl:value-of select="$name"/>
- </xsl:attribute>
- <xsl:value-of select="normalize-space($n)"/>
- </xsl:element>
- <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
- <xsl:choose>
- <xsl:when test="$name = 'creator'">
- <dc:creator>
- <xsl:value-of select="normalize-space($n)"/>
- </dc:creator>
- </xsl:when>
- <xsl:when test="$name = 'contributor'">
- <dc:contributor>
- <xsl:value-of select="normalize-space($n)"/>
- </dc:contributor>
- </xsl:when>
- <xsl:otherwise>
- <xsl:element namespace="{$dc.namespace}" name="{$name}">
- <xsl:value-of select="normalize-space($n)"/>
- </xsl:element>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:if>
- </xsl:template>
- <xsl:template match="corpcredit" mode="opf.metadata">
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="property">dcterms:contributor</xsl:attribute>
- <xsl:value-of select="normalize-space(.)"/>
- </xsl:element>
- <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
- <dc:contributor>
- <xsl:value-of select="normalize-space(.)"/>
- </dc:contributor>
- </xsl:if>
- </xsl:template>
- <xsl:template match="collab|othercredit" mode="opf.metadata">
- <xsl:variable name="content">
- <xsl:choose>
- <xsl:when test="collabname">
- <xsl:apply-templates select="collabname"/>
- </xsl:when>
- <xsl:when test="org/orgname">
- <xsl:apply-templates select="org/orgname"/>
- </xsl:when>
- <xsl:when test="orgname">
- <xsl:apply-templates select="orgname"/>
- </xsl:when>
- <xsl:when test="personname|firstname|surname|othername">
- <xsl:call-template name="person.name"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="."/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="property">dcterms:contributor</xsl:attribute>
- <xsl:value-of select="normalize-space($content)"/>
- </xsl:element>
- <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
- <dc:contributor>
- <xsl:value-of select="normalize-space($content)"/>
- </dc:contributor>
- </xsl:if>
- </xsl:template>
- <xsl:template match="date|pubdate" mode="opf.metadata">
- <xsl:variable name="date">
- <xsl:call-template name="format.meta.date">
- <xsl:with-param name="string" select="normalize-space(.)"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:if test="string-length($date) != 0">
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="property">dcterms:date</xsl:attribute>
- <xsl:value-of select="$date"/>
- </xsl:element>
-
- <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
- <dc:date>
- <xsl:value-of select="$date"/>
- </dc:date>
- </xsl:if>
- </xsl:if>
- </xsl:template>
- <!-- EPUB3 meta date should be of the form:
- YYYY, YYYY-MM or YYYY-MM-DD -->
- <xsl:template name="format.meta.date">
- <xsl:param name="string" select="''"/>
- <xsl:param name="node" select="."/>
-
- <!-- FIXME: this needs further work, so just check the
- string format and return the date string for now -->
- <xsl:variable name="normalized"
- select="translate($string, '0123456789', '##########')"/>
- <xsl:variable name="date.ok">
- <xsl:choose>
- <xsl:when test="string-length($string) = 4 and
- $normalized = '####'">1</xsl:when>
- <xsl:when test="string-length($string) = 7 and
- $normalized = '####-##'">1</xsl:when>
- <xsl:when test="string-length($string) = 10 and
- $normalized = '####-##-##'">1</xsl:when>
- <xsl:when test="string-length($string) = 10 and
- $normalized = '####-##-##'">1</xsl:when>
- <xsl:otherwise>0</xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:if test="$date.ok = 0">
- <xsl:message>
- <xsl:text>WARNING: wrong metadata date format: '</xsl:text>
- <xsl:value-of select="$string"/>
- <xsl:text>' in element </xsl:text>
- <xsl:value-of select="local-name($node/..)"/>
- <xsl:text>/</xsl:text>
- <xsl:value-of select="local-name($node)"/>
- <xsl:text>. It must be in one of these forms: </xsl:text>
- <xsl:text>YYYY, YYYY-MM, or YYYY-MM-DD.</xsl:text>
- </xsl:message>
- </xsl:if>
- <!-- return the string anyway -->
- <xsl:value-of select="$string"/>
- </xsl:template>
- <!-- Space separate the compontents of the abstract (dropping the inline markup, sadly) -->
- <xsl:template match="abstract" mode="opf.metadata">
- <xsl:variable name="content">
- <xsl:for-each select="formalpara|para|simpara|title">
- <xsl:choose>
- <xsl:when test="self::formalpara">
- <xsl:value-of select="normalize-space(string(title))"/>
- <xsl:text>: </xsl:text>
- <xsl:value-of select="normalize-space(string(para))"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="normalize-space(string(.))"/>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:if test="self::title">
- <xsl:text>:</xsl:text>
- </xsl:if>
- <xsl:if test="not(position() = last())">
- <xsl:text> </xsl:text>
- </xsl:if>
- </xsl:for-each>
- </xsl:variable>
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="property">dcterms:description</xsl:attribute>
- <xsl:copy-of select="$content"/>
- </xsl:element>
- <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
- <dc:description>
- <xsl:copy-of select="$content"/>
- </dc:description>
- </xsl:if>
- </xsl:template>
- <xsl:template match="subjectset" mode="opf.metadata">
- <xsl:apply-templates select="subject/subjectterm" mode="opf.metadata"/>
- </xsl:template>
- <xsl:template match="subjectterm" mode="opf.metadata">
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="property">dcterms:subject</xsl:attribute>
- <xsl:value-of select="normalize-space(string(.))"/>
- </xsl:element>
- <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
- <dc:subject>
- <xsl:value-of select="normalize-space(string(.))"/>
- </dc:subject>
- </xsl:if>
- </xsl:template>
- <xsl:template match="keywordset" mode="opf.metadata">
- <xsl:apply-templates select="keyword" mode="opf.metadata"/>
- </xsl:template>
- <xsl:template match="keyword" mode="opf.metadata">
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="property">dcterms:subject</xsl:attribute>
- <xsl:value-of select="normalize-space(string(.))"/>
- </xsl:element>
- <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
- <dc:subject>
- <xsl:value-of select="normalize-space(string(.))"/>
- </dc:subject>
- </xsl:if>
- </xsl:template>
- <xsl:template match="publisher" mode="opf.metadata">
- <xsl:apply-templates select="publishername" mode="opf.metadata"/>
- </xsl:template>
- <xsl:template match="publishername" mode="opf.metadata">
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="property">dcterms:publisher</xsl:attribute>
- <xsl:value-of select="normalize-space(string(.))"/>
- </xsl:element>
- <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
- <dc:publisher>
- <xsl:value-of select="normalize-space(string(.))"/>
- </dc:publisher>
- </xsl:if>
- </xsl:template>
- <xsl:template match="bibliocoverage" mode="opf.metadata">
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="property">dcterms:coverage</xsl:attribute>
- <xsl:value-of select="normalize-space(string(.))"/>
- </xsl:element>
- <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
- <dc:coverage>
- <xsl:value-of select="normalize-space(string(.))"/>
- </dc:coverage>
- </xsl:if>
- </xsl:template>
- <xsl:template match="bibliorelation" mode="opf.metadata">
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="property">dcterms:relation</xsl:attribute>
- <xsl:value-of select="normalize-space(string(.))"/>
- </xsl:element>
- <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
- <dc:relation>
- <xsl:value-of select="normalize-space(string(.))"/>
- </dc:relation>
- </xsl:if>
- </xsl:template>
- <xsl:template match="bibliosource" mode="opf.metadata">
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="property">dcterms:source</xsl:attribute>
- <xsl:value-of select="normalize-space(string(.))"/>
- </xsl:element>
- <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
- <dc:source>
- <xsl:value-of select="normalize-space(string(.))"/>
- </dc:source>
- </xsl:if>
- </xsl:template>
- <xsl:template match="copyright" mode="opf.metadata">
- <xsl:variable name="copyright.date">
- <xsl:call-template name="copyright.years">
- <xsl:with-param name="years" select="year"/>
- <xsl:with-param name="print.ranges" select="$make.year.ranges"/>
- <xsl:with-param name="single.year.ranges" select="$make.single.year.ranges"/>
- </xsl:call-template>
- </xsl:variable>
- <!-- if no docbook date element, use copyright year for single date metadata -->
- <xsl:if test="not(../date)">
- <xsl:variable name="date.content">
- <xsl:call-template name="format.meta.date">
- <xsl:with-param name="string">
- <xsl:call-template name="copyright.years">
- <xsl:with-param name="years" select="year[last()]"/>
- <xsl:with-param name="print.ranges" select="0"/>
- <xsl:with-param name="single.year.ranges" select="0"/>
- </xsl:call-template>
- </xsl:with-param>
- </xsl:call-template>
- </xsl:variable>
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="property">dcterms:date</xsl:attribute>
- <xsl:copy-of select="$date.content"/>
- </xsl:element>
- <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
- <dc:date>
- <xsl:copy-of select="$date.content"/>
- </dc:date>
- </xsl:if>
- </xsl:if>
- <xsl:variable name="rights.content">
- <xsl:call-template name="gentext">
- <xsl:with-param name="key" select="'Copyright'"/>
- </xsl:call-template>
- <xsl:call-template name="gentext.space"/>
- <xsl:text>©</xsl:text>
- <xsl:call-template name="gentext.space"/>
- <xsl:value-of select="$copyright.date"/>
- <xsl:call-template name="gentext.space"/>
- <xsl:apply-templates select="holder" mode="titlepage.mode"/>
- </xsl:variable>
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="property">dcterms:rights</xsl:attribute>
- <xsl:copy-of select="$rights.content"/>
- </xsl:element>
- <xsl:if test="$epub.include.optional.metadata.dc.elements != 0">
- <dc:rights>
- <xsl:copy-of select="$rights.content"/>
- </dc:rights>
- </xsl:if>
- <xsl:element name="meta" namespace="{$opf.namespace}">
- <xsl:attribute name="property">dcterms:rightsHolder</xsl:attribute>
- <xsl:apply-templates select="holder" mode="titlepage.mode"/>
- </xsl:element>
- </xsl:template>
- <xsl:template name="package.guide">
- <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
- <xsl:variable name="toc.params">
- <xsl:call-template name="find.path.params">
- <xsl:with-param name="node" select="."/>
- <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:if test="contains($toc.params, 'toc') or
- $info/cover or
- $info//mediaobject[@role='cover' or ancestor::cover]">
- <xsl:element namespace="{$opf.namespace}" name="guide">
- <xsl:if test="$info/cover or
- $info//mediaobject[@role='cover' or ancestor::cover]">
- <xsl:element namespace="{$opf.namespace}" name="reference">
- <xsl:attribute name="href">
- <xsl:value-of select="$epub.cover.filename" />
- </xsl:attribute>
- <xsl:attribute name="type">cover</xsl:attribute>
- <xsl:attribute name="title">Cover</xsl:attribute>
- </xsl:element>
- </xsl:if>
- <xsl:if test="contains($toc.params, 'toc')">
- <xsl:element namespace="{$opf.namespace}" name="reference">
- <xsl:attribute name="href">
- <xsl:call-template name="toc-href">
- <xsl:with-param name="node" select="."/>
- </xsl:call-template>
- </xsl:attribute>
- <xsl:attribute name="type">toc</xsl:attribute>
- <xsl:attribute name="title">Table of Contents</xsl:attribute>
- </xsl:element>
- </xsl:if>
- </xsl:element>
- </xsl:if>
- </xsl:template>
- <xsl:template name="package-identifier">
- <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
- <xsl:choose>
- <xsl:when test="$info/biblioid">
- <xsl:if test="$info/biblioid[1][@class = 'doi' or
- @class = 'isbn' or
- @class = 'isrn' or
- @class = 'istc' or
- @class = 'issn']">
- <xsl:text>urn:</xsl:text>
- <xsl:value-of select="$info/biblioid[1]/@class"/>
- <xsl:text>:</xsl:text>
- </xsl:if>
- <xsl:value-of select="normalize-space($info/biblioid[1])"/>
- </xsl:when>
- <xsl:when test="$info/isbn">
- <xsl:text>urn:isbn:</xsl:text>
- <xsl:value-of select="$info/isbn[1]"/>
- </xsl:when>
- <xsl:when test="$info/issn">
- <xsl:text>urn:issn:</xsl:text>
- <xsl:value-of select="$info/issn[1]"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:choose>
- <xsl:when test="$info/invpartnumber">
- <xsl:value-of select="$info/invpartnumber[1]"/>
- </xsl:when>
- <xsl:when test="$info/issuenum">
- <xsl:value-of select="$info/issuenum[1]"/>
- </xsl:when>
- <xsl:when test="$info/productnumber">
- <xsl:value-of select="$info/productnumber[1]"/>
- </xsl:when>
- <xsl:when test="$info/seriesvolnums">
- <xsl:value-of select="$info/seriesvolnums[1]"/>
- </xsl:when>
- <xsl:when test="$info/volumenum">
- <xsl:value-of select="$info/volumenum[1]"/>
- </xsl:when>
- <!-- Deprecated -->
- <xsl:when test="$info/pubsnumber">
- <xsl:value-of select="$info/pubsnumber[1]"/>
- </xsl:when>
- </xsl:choose>
- <xsl:text>_</xsl:text>
- <xsl:choose>
- <xsl:when test="@id">
- <xsl:value-of select="@id"/>
- </xsl:when>
- <xsl:when test="@xml:id">
- <xsl:value-of select="@xml:id"/>
- </xsl:when>
- <xsl:otherwise>
- <!-- TODO: Do UUIDs here -->
- <xsl:value-of select="generate-id(.)"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <!-- EPUB3: add epub:type attribute where appropriate -->
- <xsl:template match="*" mode="common.html.attributes">
- <xsl:param name="class" select="local-name(.)"/>
- <xsl:param name="inherit" select="0"/>
- <xsl:call-template name="generate.html.lang"/>
- <xsl:call-template name="dir">
- <xsl:with-param name="inherit" select="$inherit"/>
- </xsl:call-template>
- <xsl:apply-templates select="." mode="class.attribute">
- <xsl:with-param name="class" select="$class"/>
- </xsl:apply-templates>
- <xsl:call-template name="generate.html.title"/>
- <xsl:apply-templates select="." mode="epub.type"/>
- </xsl:template>
- <xsl:template match="*" mode="epub.type" priority="-1"/>
- <xsl:template match="chapter
- |appendix
- |epigraph
- |warning
- |preface
- |index
- |colophon
- |glossary
- |biblioentry
- |bibliography
- |dedication
- |sidebar
- |footnote
- |glossterm
- |glossdef
- |bridgehead
- |part" mode="epub.type">
- <xsl:variable name="type" select="local-name()"/>
- <xsl:if test="$epub.output.epub.types != 0">
- <xsl:attribute name="epub:type">
- <xsl:value-of select="$type"/>
- </xsl:attribute>
- </xsl:if>
- </xsl:template>
- <xsl:template match="section[parent::chapter] | sect1" mode="epub.type">
- <xsl:if test="$epub.output.epub.types != 0">
- <xsl:attribute name="epub:type">subchapter</xsl:attribute>
- </xsl:if>
- </xsl:template>
- <xsl:template match="section[not(parent::chapter)] |
- sect2 |
- sect3 |
- sect4 |
- sect5 |
- sect6" mode="epub.type">
- <xsl:if test="$epub.output.epub.types != 0">
- <xsl:attribute name="epub:type">division</xsl:attribute>
- </xsl:if>
- </xsl:template>
- <xsl:template match="note|tip|caution|important" mode="epub.type">
- <xsl:if test="$epub.output.epub.types != 0">
- <xsl:attribute name="epub:type">notice</xsl:attribute>
- </xsl:if>
- </xsl:template>
- <xsl:template match="orderedlist|itemizedlist|variablelist|simplelist" mode="epub.type">
- <xsl:if test="$epub.output.epub.types != 0">
- <xsl:attribute name="epub:type">list</xsl:attribute>
- </xsl:if>
- </xsl:template>
- <xsl:template match="listitem" mode="epub.type">
- <xsl:if test="$epub.output.epub.types != 0">
- <xsl:attribute name="epub:type">list-item</xsl:attribute>
- </xsl:if>
- </xsl:template>
- <!-- EPUB3: to add attributes to root output element -->
- <xsl:template name="root.attributes">
- <!-- collect and output all namespace declarations -->
- <xsl:call-template name="all.namespaces"/>
- </xsl:template>
- <xsl:template name="all.namespaces">
- <!-- add the epub3 namespaces to the top output element -->
- <xsl:variable name="temp">
- <epub:foo/>
- <m:foo/>
- <pls:foo/>
- <ssml:foo/>
- <svg:foo/>
- </xsl:variable>
- <xsl:variable name="nodes" select="exsl:node-set($temp)"/>
- <xsl:for-each select="$nodes//*/namespace::*">
- <xsl:copy-of select="."/>
- </xsl:for-each>
- </xsl:template>
- <xsl:template name="add.package.namespaces">
- <!-- add the epub3 package namespaces to the top output element -->
- <xsl:variable name="temp">
- <dc:foo/>
- <dcterms:foo/>
- </xsl:variable>
- <xsl:variable name="nodes" select="exsl:node-set($temp)"/>
- <xsl:for-each select="$nodes//*[local-name(.) ='foo']/namespace::*">
- <xsl:if test="contains(., 'purl.org')">
- <xsl:copy-of select="."/>
- </xsl:if>
- </xsl:for-each>
- </xsl:template>
- <xsl:template name="footnotes.attributes">
- <xsl:if test="$epub.output.epub.types != 0">
- <xsl:attribute name="epub:type">footnotes</xsl:attribute>
- </xsl:if>
- </xsl:template>
- <xsl:template name="package.manifest">
- <xsl:element name="manifest" namespace="{$opf.namespace}">
- <xsl:if test="$epub.include.ncx != 0">
- <xsl:call-template name="manifest.ncx"/>
- </xsl:if>
- <xsl:call-template name="manifest.fonts"/>
- <xsl:call-template name="manifest.toc"/>
- <xsl:call-template name="manifest.css"/>
- <xsl:call-template name="manifest.cover"/>
- <xsl:call-template name="manifest.other.items"/>
- <xsl:call-template name="manifest.content.items"/>
- <xsl:call-template name="user.manifest.items"/>
- </xsl:element>
- </xsl:template>
- <xsl:template name="user.manifest.items"/>
- <xsl:template name="manifest.css">
- <xsl:if test="$html.stylesheet != ''">
- <xsl:call-template name="css.item">
- <xsl:with-param name="stylesheets" select="$html.stylesheet"/>
- </xsl:call-template>
- </xsl:if>
- <xsl:if test="string-length($docbook.css.source) != 0">
- <xsl:variable name="dfilename">
- <xsl:call-template name="css.output.filename">
- <xsl:with-param name="src" select="$docbook.css.source"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:element namespace="{$opf.namespace}" name="item">
- <xsl:attribute name="media-type">text/css</xsl:attribute>
- <xsl:attribute name="id">docbook-css</xsl:attribute>
- <xsl:attribute name="href">
- <xsl:value-of select="$dfilename"/>
- </xsl:attribute>
- </xsl:element>
- </xsl:if>
- <xsl:if test="string-length($custom.css.source) != 0">
- <xsl:variable name="cfilename">
- <xsl:call-template name="css.output.filename">
- <xsl:with-param name="src" select="$custom.css.source"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:element namespace="{$opf.namespace}" name="item">
- <xsl:attribute name="media-type">text/css</xsl:attribute>
- <xsl:attribute name="id">custom-css</xsl:attribute>
- <xsl:attribute name="href">
- <xsl:value-of select="$cfilename"/>
- </xsl:attribute>
- </xsl:element>
- </xsl:if>
- </xsl:template>
- <xsl:template name="css.item">
- <xsl:param name="stylesheets" select="''"/>
- <xsl:param name="count" select="1"/>
- <xsl:choose>
- <xsl:when test="contains($stylesheets, ' ')">
- <xsl:variable name="css.filename" select="substring-before($stylesheets, ' ')"/>
- <xsl:if test="$css.filename != ''">
- <xsl:element namespace="{$opf.namespace}" name="item">
- <xsl:attribute name="media-type">text/css</xsl:attribute>
- <xsl:attribute name="id">
- <xsl:text>html-css</xsl:text>
- <xsl:if test="$count > 1">
- <xsl:value-of select="$count"/>
- </xsl:if>
- </xsl:attribute>
- <xsl:attribute name="href">
- <xsl:value-of select="$css.filename"/>
- </xsl:attribute>
- </xsl:element>
- </xsl:if>
- <xsl:call-template name="css.item">
- <xsl:with-param name="stylesheets" select="substring-after($stylesheets, ' ')"/>
- <xsl:with-param name="count" select="$count + 1"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:if test="$stylesheets != ''">
- <xsl:element namespace="{$opf.namespace}" name="item">
- <xsl:attribute name="media-type">text/css</xsl:attribute>
- <xsl:attribute name="id">
- <xsl:text>html-css</xsl:text>
- <xsl:if test="$count > 1">
- <xsl:value-of select="$count"/>
- </xsl:if>
- </xsl:attribute>
- <xsl:attribute name="href">
- <xsl:value-of select="$stylesheets"/>
- </xsl:attribute>
- </xsl:element>
- </xsl:if>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template name="manifest.ncx">
- <xsl:element name="item" namespace="{$opf.namespace}">
- <xsl:attribute name="id">
- <xsl:value-of select="$epub.ncx.manifest.id"/>
- </xsl:attribute>
- <xsl:attribute name="href">
- <xsl:value-of select="$epub.ncx.filename"/>
- </xsl:attribute>
- <xsl:attribute name="media-type">
- <xsl:value-of select="$epub.ncx.mediatype"/>
- </xsl:attribute>
- </xsl:element>
- </xsl:template>
- <xsl:template name="manifest.fonts"/>
- <!--Misc items in the manifest based on content -->
- <xsl:template name="manifest.other.items">
- </xsl:template>
- <xsl:template name="manifest.cover">
- <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
- <xsl:variable name="cover.image"
- select="$info//mediaobject[@role='cover' or ancestor::cover]"/>
- <xsl:if test="$cover.image">
- <!-- generate the manifest link to that page -->
- <xsl:variable name="olist" select="$cover.image/imageobject|$cover.image/imageobjectco
- |$cover.image/videoobject|$cover.image/audioobject
- |$cover.image/textobject"/>
-
- <xsl:variable name="object.index">
- <xsl:call-template name="select.mediaobject.index">
- <xsl:with-param name="olist" select="$olist"/>
- <xsl:with-param name="count" select="1"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="object" select="$olist[position() = $object.index]"/>
- <xsl:variable name="output_filename">
- <xsl:call-template name="mediaobject.filename">
- <xsl:with-param name="object" select="$object"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="image.filename">
- <xsl:if test="$img.src.path != '' and
- not(starts-with($output_filename, '/')) and
- not(contains($output_filename, '://'))">
- <xsl:value-of select="$img.src.path"/>
- </xsl:if>
- <xsl:value-of select="$output_filename"/>
- </xsl:variable>
- <xsl:variable name="image.extension">
- <xsl:call-template name="filename-extension">
- <xsl:with-param name="filename" select="$image.filename"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="image.type">
- <xsl:call-template name="graphic.format.content-type">
- <xsl:with-param name="format" select="translate($image.extension,
- &lowercase;, &uppercase;)"/>
- </xsl:call-template>
- </xsl:variable>
- <!-- Reference to cover html file -->
- <xsl:element namespace="{$opf.namespace}" name="item">
- <xsl:attribute name="id">
- <xsl:value-of select="$epub.cover.filename.id"/>
- </xsl:attribute>
- <xsl:attribute name="href">
- <xsl:value-of select="$epub.cover.filename"/>
- </xsl:attribute>
- <xsl:attribute name="media-type">
- <xsl:value-of select="$epub.xhtml.mediatype"/>
- </xsl:attribute>
- </xsl:element>
- <!-- special item with property="cover-image" -->
- <xsl:element namespace="{$opf.namespace}" name="item">
- <xsl:attribute name="id">
- <xsl:value-of select="$epub.cover.image.id"/>
- </xsl:attribute>
- <xsl:attribute name="properties">cover-image</xsl:attribute>
- <xsl:attribute name="href">
- <xsl:value-of select="$image.filename"/>
- </xsl:attribute>
- <xsl:if test="$image.type">
- <xsl:attribute name="media-type">
- <xsl:value-of select="$image.type"/>
- </xsl:attribute>
- </xsl:if>
- </xsl:element>
- <!-- And generate the cover html file -->
- <xsl:apply-templates select="$cover.image"/>
- </xsl:if>
- </xsl:template>
- <xsl:template name="manifest.toc">
- <xsl:variable name="toc.params">
- <xsl:call-template name="find.path.params">
- <xsl:with-param name="node" select="."/>
- <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:if test="contains($toc.params, 'toc')">
- <xsl:element namespace="{$opf.namespace}" name="item">
- <xsl:attribute name="id">
- <xsl:value-of select="$epub.html.toc.id"/>
- </xsl:attribute>
- <xsl:attribute name="properties">nav</xsl:attribute>
- <xsl:attribute name="media-type">
- <xsl:value-of select="$epub.xhtml.mediatype"/>
- </xsl:attribute>
- <xsl:attribute name="href">
- <xsl:call-template name="toc-href">
- <xsl:with-param name="node" select="."/>
- </xsl:call-template>
- </xsl:attribute>
- </xsl:element>
- </xsl:if>
- </xsl:template>
- <xsl:template name="toc-href">
- <xsl:param name="node" select="."/>
- <!-- FIXME -->
- <xsl:apply-templates select="$node" mode="recursive-chunk-filename">
- <xsl:with-param name="recursive" select="true()"/>
- </xsl:apply-templates>
- <xsl:text>-toc</xsl:text>
- <xsl:value-of select="$html.ext"/>
- </xsl:template>
- <xsl:template match="*" mode="recursive-chunk-filename">
- <!-- placeholder for real template in chunking stylesheet -->
- <xsl:value-of select="concat(local-name(.), '-', generate-id(.))"/>
- </xsl:template>
- <xsl:template name="manifest.content.items">
- <xsl:apply-templates select="." mode="package.manifest"/>
- <xsl:call-template name="manifest.images"/>
- </xsl:template>
- <xsl:template match="text()" mode="package.manifest"/>
- <xsl:template match="mediaobject|mediaobjectco|inlinemediaobject" priority="1"
- mode="package.manifest">
- <!-- These are handled out of line so a unique list is created
- to remove duplicate references -->
- </xsl:template>
- <xsl:template match="*" mode="package.manifest">
- <xsl:variable name="is.chunk">
- <xsl:call-template name="chunk">
- <xsl:with-param name="node" select="."/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:if test="$is.chunk != 0">
- <xsl:variable name="href">
- <xsl:call-template name="href.target.with.base.dir">
- <xsl:with-param name="context" select="/"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="id" select="concat($epub.package.id.prefix, generate-id())"/>
- <xsl:variable name="properties.set">
- <xsl:call-template name="svg.property"/>
- <xsl:text> </xsl:text>
- <xsl:call-template name="mathml.property"/>
- </xsl:variable>
- <xsl:variable name="properties" select="normalize-space($properties.set)"/>
- <xsl:element namespace="{$opf.namespace}" name="item">
- <xsl:attribute name="id">
- <xsl:value-of select="$id"/>
- </xsl:attribute>
- <xsl:attribute name="href">
- <xsl:value-of select="$href"/>
- </xsl:attribute>
- <xsl:attribute name="media-type">application/xhtml+xml</xsl:attribute>
- <xsl:if test="string-length($properties) != 0">
- <xsl:attribute name="properties">
- <xsl:value-of select="$properties"/>
- </xsl:attribute>
- </xsl:if>
- </xsl:element>
- </xsl:if>
- <xsl:apply-templates mode="package.manifest"/>
- </xsl:template>
- <xsl:template name="svg.property">
- <xsl:param name="this.chunk" select="."/>
- <xsl:variable name="genid" select="generate-id($this.chunk)"/>
- <!-- get the chunkfast div element for this chunk -->
- <xsl:variable name="div" select="$chunkset[@id=$genid or @xml:id=$genid]"/>
- <!-- get the chunkfast div element the next chunk -->
- <xsl:variable name="nextdiv"
- select="($div/following-sibling::cf:div|
- $div/following::cf:div|
- $div/cf:div)[1]"/>
- <!-- get the element corresponding to the next chunk -->
- <xsl:variable name="next.chunk" select="key('genid', ($nextdiv/@id|$nextdiv/@xml:id)[1])"/>
- <xsl:choose>
- <xsl:when test="$next.chunk">
- <xsl:variable name="this.imagedata"
- select="$this.chunk//mediaobject"/>
- <xsl:variable name="before.next"
- select="$next.chunk/preceding::mediaobject"/>
-
- <!-- select for an SVG imagedata in the intersection of them -->
- <xsl:variable name="mediaobject.set"
- select="$this.imagedata[count(.|$before.next) = count($before.next)]"/>
- <xsl:variable name="svg.imagedata">
- <xsl:for-each select="$mediaobject.set">
- <xsl:variable name="olist" select="imageobject[not(@role = 'poster')] |
- imageobjectco"/>
- <xsl:variable name="mediaobject.index">
- <xsl:call-template name="select.mediaobject.index">
- <xsl:with-param name="olist" select="$olist"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="object" select="$olist[position() = $mediaobject.index]"/>
- <xsl:if test="$object/imagedata[contains(
- substring(@fileref, string-length(@fileref)-3,4), '.svg')]">
- <xsl:text>svg</xsl:text>
- </xsl:if>
- </xsl:for-each>
- </xsl:variable>
-
- <xsl:if test="contains($svg.imagedata, 'svg')">
- <xsl:text>svg</xsl:text>
- </xsl:if>
- </xsl:when>
- <xsl:otherwise>
- <xsl:variable name="mediaobject.set"
- select="$this.chunk//mediaobject"/>
- <xsl:variable name="svg.imagedata">
- <xsl:for-each select="$mediaobject.set">
- <xsl:variable name="olist" select="imageobject[not(@role = 'poster')] |
- imageobjectco"/>
- <xsl:variable name="mediaobject.index">
- <xsl:call-template name="select.mediaobject.index">
- <xsl:with-param name="olist" select="$olist"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="object" select="$olist[position() = $mediaobject.index]"/>
- <xsl:if test="$object/imagedata[contains(
- substring(@fileref, string-length(@fileref)-3,4), '.svg')]">
- <xsl:text>svg</xsl:text>
- </xsl:if>
- </xsl:for-each>
- </xsl:variable>
-
- <xsl:if test="contains($svg.imagedata, 'svg')">
- <xsl:text>svg</xsl:text>
- </xsl:if>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template name="mathml.property">
- <xsl:param name="this.chunk" select="."/>
- <xsl:variable name="genid" select="generate-id($this.chunk)"/>
- <!-- get the chunkfast div element for this chunk -->
- <xsl:variable name="div" select="$chunkset[@id=$genid or @xml:id=$genid]"/>
- <!-- get the chunkfast div element the next chunk -->
- <xsl:variable name="nextdiv"
- select="($div/following-sibling::cf:div|
- $div/following::cf:div|
- $div/cf:div)[1]"/>
- <!-- get the element corresponding to the next chunk -->
- <xsl:variable name="next.chunk" select="key('genid', ($nextdiv/@id|$nextdiv/@xml:id)[1])"/>
- <xsl:variable name="this.math"
- select="$this.chunk//m:*"/>
- <xsl:variable name="before.next"
- select="$next.chunk/preceding::m:*"/>
-
- <!-- select for an SVG imagedata in the intersection of them -->
- <xsl:variable name="intersection"
- select="$this.math[count(.|$before.next) = count($before.next)]"/>
- <xsl:if test="count($intersection) != 0">
- <xsl:text>mathml</xsl:text>
- </xsl:if>
- </xsl:template>
- <xsl:template name="manifest.image.item">
- </xsl:template>
- <!-- Need a uniqued list of images -->
- <xsl:template name="manifest.images">
- <xsl:message>Generating image list ...</xsl:message>
- <xsl:variable name="imagelist">
- <xsl:choose>
- <xsl:when test="$rootid != ''">
- <xsl:apply-templates select="key('id', $rootid)" mode="enumerate-images"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates select="/" mode="enumerate-images"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="$exsl.node.set.available != 0 and
- function-available('set:distinct')">
- <xsl:for-each select="set:distinct(exsl:node-set($imagelist)/*)">
- <xsl:if test="string-length(tmp-href) != 0">
- <!-- convert the child elements to attributes -->
- <xsl:element name="item" namespace="{$opf.namespace}">
- <xsl:attribute name="id">
- <xsl:value-of select="generate-id()"/>
- </xsl:attribute>
- <xsl:attribute name="href">
- <xsl:value-of select="tmp-href"/>
- </xsl:attribute>
- <xsl:attribute name="media-type">
- <xsl:value-of select="media-type"/>
- </xsl:attribute>
- </xsl:element>
- </xsl:if>
- </xsl:for-each>
- </xsl:when>
- <xsl:when test="$exsl.node.set.available != 0">
- <xsl:for-each select="exsl:node-set($imagelist)/*">
- <xsl:element name="item" namespace="{$opf.namespace}">
- <xsl:attribute name="id">
- <xsl:value-of select="generate-id()"/>
- </xsl:attribute>
- <xsl:attribute name="href">
- <xsl:value-of select="tmp-href"/>
- </xsl:attribute>
- <xsl:attribute name="media-type">
- <xsl:value-of select="media-type"/>
- </xsl:attribute>
- </xsl:element>
- </xsl:for-each>
- </xsl:when>
- <xsl:otherwise>
- <xsl:message terminate="yes">
- <xsl:text>ERROR: cannot process images list without </xsl:text>
- <xsl:text>exsl:node-set() function</xsl:text>
- </xsl:message>
- <!-- cannot do this without node-set() -->
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template match="*" mode="enumerate-images">
- <xsl:apply-templates mode="enumerate-images"/>
- </xsl:template>
- <xsl:template match="text()" mode="enumerate-images"/>
- <xsl:template match="graphic|inlinegraphic[@format!='linespecific']"
- mode="enumerate-images">
- </xsl:template>
- <!-- cover image handled separates to give it an extra property attribute -->
- <xsl:template match="mediaobject[@role='cover' or ancestor::cover]"
- mode="enumerate-images"/>
- <xsl:template match="mediaobject|inlinemediaobject" mode="enumerate-images">
- <xsl:variable name="olist"
- select="imageobject[not(@role = 'poster')]
- |imageobjectco
- |videoobject
- |audioobject
- |textobject"/>
-
- <xsl:variable name="object.index">
- <xsl:call-template name="select.mediaobject.index">
- <xsl:with-param name="olist" select="$olist"/>
- <xsl:with-param name="count" select="1"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="object" select="$olist[position() = $object.index]"/>
- <xsl:apply-templates select="$object" mode="enumerate-images"/>
- <!-- also include a poster image if present -->
- <xsl:apply-templates select="imageobject[@role = 'poster']" mode="enumerate-images"/>
- </xsl:template>
- <xsl:template match="imageobject|videoobject|audioobject" mode="enumerate-images">
- <xsl:param name="object" select="."/>
- <xsl:if test="$object">
- <xsl:variable name="output_filename">
- <xsl:call-template name="mediaobject.filename">
- <xsl:with-param name="object" select="$object"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="image.filename">
- <xsl:if test="$img.src.path != '' and
- not(starts-with($output_filename, '/')) and
- not(contains($output_filename, '://'))">
- <xsl:value-of select="$img.src.path"/>
- </xsl:if>
- <xsl:value-of select="$output_filename"/>
- </xsl:variable>
- <xsl:variable name="image.extension">
- <xsl:call-template name="filename-extension">
- <xsl:with-param name="filename" select="$image.filename"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="image.type">
- <xsl:call-template name="graphic.format.content-type">
- <xsl:with-param name="format" select="translate($image.extension,
- &lowercase;, &uppercase;)"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:element name="tmp-filename" namespace="">
- <xsl:element name="tmp-href" namespace="">
- <xsl:value-of select="$image.filename"/>
- </xsl:element>
- <xsl:element name="media-type" namespace="">
- <xsl:value-of select="$image.type"/>
- </xsl:element>
- </xsl:element>
- </xsl:if>
- </xsl:template>
-
- <!-- Add in the generated images -->
- <xsl:template match="note|caution|warning|important|tip" mode="enumerate-images">
- <xsl:if test="$admon.graphics != 0">
- <xsl:variable name="image.filename">
- <xsl:call-template name="admon.graphic"/>
- </xsl:variable>
- <xsl:variable name="image.type">
- <xsl:call-template name="graphic.format.content-type">
- <xsl:with-param name="format" select="translate(
- substring-after($admon.graphics.extension,'.'),
- &lowercase;, &uppercase;)"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:element name="tmp-filename" namespace="">
- <xsl:element name="tmp-href" namespace="">
- <xsl:value-of select="$image.filename"/>
- </xsl:element>
- <xsl:element name="media-type" namespace="">
- <xsl:value-of select="$image.type"/>
- </xsl:element>
- </xsl:element>
- </xsl:if>
- </xsl:template>
- <xsl:template match="callout" mode="enumerate-images">
- <!-- process arearefs to get name of callout bug image files -->
- <xsl:if test="$callout.graphics != 0">
- <xsl:variable name="arearefs">
- <xsl:call-template name="callout.arearefs">
- <xsl:with-param name="arearefs" select="@arearefs"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="nodes" select="exsl:node-set($arearefs)"/>
- <xsl:for-each select="$nodes//*[@src]">
- <xsl:variable name="image.filename" select="@src"/>
- <xsl:variable name="image.type">
- <xsl:call-template name="graphic.format.content-type">
- <xsl:with-param name="format" select="translate(
- substring-after($callout.graphics.extension,'.'),
- &lowercase;, &uppercase;)"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:element name="tmp-filename" namespace="">
- <xsl:element name="tmp-href" namespace="">
- <xsl:value-of select="$image.filename"/>
- </xsl:element>
- <xsl:element name="media-type" namespace="">
- <xsl:value-of select="$image.type"/>
- </xsl:element>
- </xsl:element>
- </xsl:for-each>
- </xsl:if>
- </xsl:template>
- <xsl:template match="co" mode="enumerate-images">
- <!-- process co to get name of callout bug image file -->
- <xsl:if test="$callout.graphics != 0">
- <xsl:variable name="result">
- <xsl:apply-templates select="." mode="callout-bug"/>
- </xsl:variable>
- <xsl:variable name="nodes" select="exsl:node-set($result)"/>
- <xsl:for-each select="$nodes//*[@src]">
- <xsl:variable name="image.filename" select="@src"/>
- <xsl:variable name="image.type">
- <xsl:call-template name="graphic.format.content-type">
- <xsl:with-param name="format" select="translate(
- substring-after($callout.graphics.extension,'.'),
- &lowercase;, &uppercase;)"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:element name="tmp-filename" namespace="">
- <xsl:element name="tmp-href" namespace="">
- <xsl:value-of select="$image.filename"/>
- </xsl:element>
- <xsl:element name="media-type" namespace="">
- <xsl:value-of select="$image.type"/>
- </xsl:element>
- </xsl:element>
- </xsl:for-each>
- </xsl:if>
- </xsl:template>
- <!-- ======================================================== -->
- <!-- NCX templates are for backwards compatibility with EPUB2 -->
- <!-- ======================================================== -->
- <xsl:template name="ncx">
- <xsl:message>Generating NCX file ...</xsl:message>
- <xsl:call-template name="write.chunk">
- <xsl:with-param name="filename">
- <xsl:value-of select="$epub.ncx.pathname" />
- </xsl:with-param>
- <xsl:with-param name="method" select="'xml'" />
- <xsl:with-param name="encoding" select="'utf-8'" />
- <xsl:with-param name="indent" select="'no'" />
- <xsl:with-param name="quiet" select="$chunk.quietly" />
- <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
- <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
- <xsl:with-param name="content">
- <xsl:element name="ncx" namespace="{$ncx.namespace}">
- <xsl:attribute name="version">2005-1</xsl:attribute>
- <!-- Via Martin Goerner: On covers: the IDPF2.0 standard unfortunately does not have a provision for
- covers. We had to add one and we did so in conjunction with the IDPF and
- various publishers. The tag chosen to define the covers is:
- <meta name="cover" content="-reference to a manifest item-">
- Then, we also added a bit of logic to get rid cleanly of the HTML cover
- people usually add because the logical cover is not specced by the IDPF. So,
- if the HTML cover item is marked linear="no" AND there is a guide item of
- type="cover" pointing to it AND there is a logical cover specified in a
- <meta name="cover"> tag, THEN, the HTML cover is discarded. -->
- <xsl:element name="head" namespace="{$ncx.namespace}">
- <xsl:if test="/*/*[cover or contains(name(.), 'info')]//mediaobject[@role='cover' or ancestor::cover]">
- <xsl:element name="meta" namespace="{$ncx.namespace}">
- <xsl:attribute name="name">cover</xsl:attribute>
- <xsl:attribute name="content">
- <xsl:value-of select="$epub.cover.filename.id"/>
- </xsl:attribute>
- </xsl:element>
- </xsl:if>
- <xsl:element name="meta" namespace="{$ncx.namespace}">
- <xsl:attribute name="name">dtb:uid</xsl:attribute>
- <xsl:attribute name="content"><xsl:call-template name="package-identifier"/></xsl:attribute>
- </xsl:element>
- </xsl:element>
- <xsl:choose>
- <xsl:when test="$rootid != ''">
- <xsl:variable name="title">
- <xsl:if test="$epub.autolabel != 0">
- <xsl:variable name="label.markup">
- <xsl:apply-templates select="key('id',$rootid)" mode="label.markup" />
- </xsl:variable>
- <xsl:if test="normalize-space($label.markup)">
- <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
- </xsl:if>
- </xsl:if>
- <xsl:apply-templates select="key('id',$rootid)" mode="title.markup" />
- </xsl:variable>
- <xsl:variable name="href">
- <xsl:call-template name="href.target.with.base.dir">
- <xsl:with-param name="object" select="key('id',$rootid)" />
- </xsl:call-template>
- </xsl:variable>
- <xsl:element name="docTitle" namespace="{$ncx.namespace}">
- <xsl:element name="text" namespace="{$ncx.namespace}"><xsl:value-of select="normalize-space($title)" /> </xsl:element>
- </xsl:element>
- <xsl:element name="navMap" namespace="{$ncx.namespace}">
- <xsl:apply-templates select="key('id',$rootid)/*" mode="ncx" />
- </xsl:element>
- </xsl:when>
- <xsl:otherwise>
- <xsl:variable name="title">
- <xsl:if test="$epub.autolabel != 0">
- <xsl:variable name="label.markup">
- <xsl:apply-templates select="/*" mode="label.markup" />
- </xsl:variable>
- <xsl:if test="normalize-space($label.markup)">
- <xsl:value-of select="concat($label.markup,$autotoc.label.separator)" />
- </xsl:if>
- </xsl:if>
- <xsl:apply-templates select="/*" mode="title.markup" />
- </xsl:variable>
- <xsl:variable name="href">
- <xsl:call-template name="href.target.with.base.dir">
- <xsl:with-param name="object" select="/" />
- </xsl:call-template>
- </xsl:variable>
- <xsl:element name="docTitle" namespace="{$ncx.namespace}">
- <xsl:element name="text" namespace="{$ncx.namespace}">
- <xsl:value-of select="normalize-space($title)" />
- </xsl:element>
- </xsl:element>
- <xsl:element name="navMap" namespace="{$ncx.namespace}">
- <xsl:choose>
- <xsl:when test="$root.is.a.chunk != '0'">
- <xsl:apply-templates select="/*" mode="ncx" />
- <xsl:apply-templates select="/*/*" mode="ncx" />
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates select="/*/*" mode="ncx" />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:element>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:element>
- </xsl:with-param>
- </xsl:call-template>
- </xsl:template>
- <xsl:template match="book|
- article|
- topic|
- part|
- reference|
- preface|
- chapter|
- bibliography|
- appendix|
- glossary|
- section|
- sect1|
- sect2|
- sect3|
- sect4|
- sect5|
- refentry|
- colophon|
- bibliodiv[title]|
- setindex|
- index"
- mode="ncx">
- <xsl:variable name="depth" select="count(ancestor::*)"/>
- <xsl:variable name="title">
- <xsl:if test="$epub.autolabel != 0">
- <xsl:variable name="label.markup">
- <xsl:apply-templates select="." mode="label.markup" />
- </xsl:variable>
- <xsl:if test="normalize-space($label.markup)">
- <xsl:value-of
- select="concat($label.markup,$autotoc.label.separator)" />
- </xsl:if>
- </xsl:if>
- <xsl:apply-templates select="." mode="title.markup" />
- </xsl:variable>
- <xsl:variable name="href">
- <xsl:call-template name="href.target.with.base.dir">
- <xsl:with-param name="context" select="/" />
- <!-- Generate links relative to the location of root file/toc.xml file -->
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="id">
- <xsl:value-of select="generate-id(.)"/>
- </xsl:variable>
- <xsl:variable name="order">
- <xsl:value-of select="$depth +
- count(preceding::part|
- preceding::reference|
- preceding::book[parent::set]|
- preceding::preface|
- preceding::chapter|
- preceding::bibliography|
- preceding::appendix|
- preceding::article|
- preceding::topic|
- preceding::glossary|
- preceding::section[not(parent::partintro)]|
- preceding::sect1[not(parent::partintro)]|
- preceding::sect2[not(ancestor::partintro)]|
- preceding::sect3[not(ancestor::partintro)]|
- preceding::sect4[not(ancestor::partintro)]|
- preceding::sect5[not(ancestor::partintro)]|
- preceding::refentry|
- preceding::colophon|
- preceding::bibliodiv[title]|
- preceding::index)"/>
- </xsl:variable>
- <xsl:element name="navPoint" namespace="{$ncx.namespace}">
- <xsl:attribute name="id">
- <xsl:value-of select="$id"/>
- </xsl:attribute>
- <xsl:attribute name="playOrder">
- <xsl:choose>
- <xsl:when test="/*[self::set]">
- <xsl:value-of select="$order"/>
- </xsl:when>
- <xsl:when test="$root.is.a.chunk != '0'">
- <xsl:value-of select="$order + 1"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$order - 0"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:attribute>
- <xsl:element name="navLabel" namespace="{$ncx.namespace}">
- <xsl:element name="text" namespace="{$ncx.namespace}"><xsl:value-of select="normalize-space($title)"/> </xsl:element>
- </xsl:element>
- <xsl:element name="content" namespace="{$ncx.namespace}">
- <xsl:attribute name="src">
- <xsl:value-of select="$href"/>
- </xsl:attribute>
- </xsl:element>
- <xsl:if test="$depth != 0">
- <!-- Don't recurse on root element, but treat it as a single point so
- the progress bar shows all top level children -->
- <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"/>
- </xsl:if>
- </xsl:element>
- </xsl:template>
- <xsl:template match="text()" mode="ncx" />
- <xsl:template name="package.spine">
- <xsl:variable name="toc.params">
- <xsl:call-template name="find.path.params">
- <xsl:with-param name="node" select="."/>
- <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:element namespace="http://www.idpf.org/2007/opf" name="spine">
- <xsl:if test="$epub.include.ncx != 0">
- <xsl:attribute name="toc">
- <xsl:value-of select="$epub.ncx.manifest.id"/>
- </xsl:attribute>
- </xsl:if>
- <xsl:call-template name="spine.cover"/>
- <xsl:if test="contains($toc.params, 'toc')">
- <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
- <xsl:attribute name="idref"> <xsl:value-of select="$epub.html.toc.id"/> </xsl:attribute>
- <xsl:attribute name="linear">yes</xsl:attribute>
- </xsl:element>
- </xsl:if>
- <!-- TODO: be nice to have a idref="titlepage" here -->
- <xsl:choose>
- <xsl:when test="$root.is.a.chunk != '0'">
- <xsl:apply-templates select="/*" mode="package.spine"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates select="/*/*" mode="package.spine"/>
- </xsl:otherwise>
- </xsl:choose>
-
- </xsl:element>
- </xsl:template>
- <xsl:template name="spine.cover">
- <xsl:variable name="info" select="./*[contains(local-name(.), 'info')][1]"/>
- <xsl:variable name="cover.image"
- select="$info//mediaobject[@role='cover' or ancestor::cover]"/>
- <xsl:if test="$cover.image">
- <!-- generate the spine reference to that cover html file -->
- <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
- <xsl:attribute name="idref">
- <xsl:value-of select="$epub.cover.filename.id"/>
- </xsl:attribute>
- <xsl:attribute name="linear">
- <xsl:choose>
- <xsl:when test="$epub.cover.linear">
- <xsl:text>yes</xsl:text>
- </xsl:when>
- <xsl:otherwise>no</xsl:otherwise>
- </xsl:choose>
- </xsl:attribute>
- </xsl:element>
- </xsl:if>
- </xsl:template>
- <xsl:template match="*" mode="package.spine">
- <xsl:variable name="is.chunk">
- <xsl:call-template name="chunk">
- <xsl:with-param name="node" select="."/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:if test="$is.chunk != 0">
- <xsl:element namespace="http://www.idpf.org/2007/opf" name="itemref">
- <xsl:attribute name="idref">
- <xsl:value-of select="concat($epub.package.id.prefix, generate-id(.))"/>
- </xsl:attribute>
- </xsl:element>
- <xsl:apply-templates select="*|.//refentry" mode="package.spine"/>
- </xsl:if>
- </xsl:template>
- <xsl:template match="*" mode="container">
- <xsl:call-template name="container"/>
- </xsl:template>
- <xsl:template name="container">
- <!-- The path in rootfile does not include all of base.dir, only the last part -->
- <xsl:variable name="full-path-dir">
- <xsl:call-template name="filename-basename">
- <xsl:with-param name="filename" select="$chunk.base.dir"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:call-template name="write.chunk">
- <xsl:with-param name="filename">
- <xsl:value-of select="$epub.container.pathname" />
- </xsl:with-param>
- <xsl:with-param name="method" select="'xml'" />
- <xsl:with-param name="encoding" select="'utf-8'" />
- <xsl:with-param name="indent" select="'no'" />
- <xsl:with-param name="quiet" select="$chunk.quietly" />
- <xsl:with-param name="doctype-public" select="''"/> <!-- intentionally blank -->
- <xsl:with-param name="doctype-system" select="''"/> <!-- intentionally blank -->
- <xsl:with-param name="content">
- <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="container">
- <xsl:attribute name="version">1.0</xsl:attribute>
- <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="rootfiles">
- <xsl:element namespace="urn:oasis:names:tc:opendocument:xmlns:container" name="rootfile">
- <xsl:attribute name="full-path">
- <xsl:value-of
- select="concat($full-path-dir, $epub.package.filename)"/>
- </xsl:attribute>
- <xsl:attribute name="media-type">
- <xsl:text>application/oebps-package+xml</xsl:text>
- </xsl:attribute>
- </xsl:element>
- </xsl:element>
- </xsl:element>
- </xsl:with-param>
- </xsl:call-template>
- </xsl:template>
- <xsl:template name="mimetype">
- <xsl:call-template name="write.text.chunk">
- <xsl:with-param name="filename" select="$epub.mimetype.pathname"/>
- <xsl:with-param name="content" select="$epub.mimetype.value"/>
- </xsl:call-template>
- </xsl:template>
- <xsl:template match="mediaobject[@role='cover' or ancestor::cover]">
- <xsl:call-template name="write.chunk">
- <xsl:with-param name="filename">
- <xsl:value-of select="$epub.cover.pathname" />
- </xsl:with-param>
- <xsl:with-param name="method" select="'xml'" />
- <xsl:with-param name="encoding" select="'utf-8'" />
- <xsl:with-param name="indent" select="'no'" />
- <xsl:with-param name="quiet" select="$chunk.quietly" />
- <xsl:with-param name="content">
- <xsl:element namespace="http://www.w3.org/1999/xhtml" name="html">
- <xsl:element namespace="http://www.w3.org/1999/xhtml" name="head">
- <xsl:element namespace="http://www.w3.org/1999/xhtml" name="title">Cover</xsl:element>
- <xsl:element namespace="http://www.w3.org/1999/xhtml" name="style">
- <xsl:attribute name="type">text/css</xsl:attribute>
- <!-- Help the cover image scale nicely in the CSS then apply a max-width to look better in Adobe Digital Editions -->
- <xsl:text> img { max-width: 100%; }</xsl:text>
- </xsl:element>
- </xsl:element>
- <xsl:element namespace="http://www.w3.org/1999/xhtml" name="body">
- <xsl:element namespace="http://www.w3.org/1999/xhtml" name="div">
- <xsl:attribute name="id">
- <xsl:value-of select="$epub.cover.image.id"/>
- </xsl:attribute>
- <xsl:choose>
- <xsl:when test="imageobject[@role='front-large']">
- <xsl:apply-templates select="imageobject[@role='front-large']"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates select="imageobject[1]"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:element>
- <!-- If this is defined as an explicit cover page, then process
- any remaining text -->
- <xsl:if test="ancestor::cover">
- <xsl:apply-templates select="ancestor::cover/para"/>
- </xsl:if>
- </xsl:element>
- </xsl:element>
- </xsl:with-param>
- </xsl:call-template>
- </xsl:template>
- <!-- EPUB3: use <nav> and <ol> in TOC lists -->
- <xsl:template name="make.toc">
- <xsl:param name="toc-context" select="."/>
- <xsl:param name="toc.title.p" select="true()"/>
- <xsl:param name="nodes" select="/NOT-AN-ELEMENT"/>
- <xsl:variable name="nodes.plus" select="$nodes | qandaset"/>
- <xsl:variable name="toc.title">
- <xsl:if test="$toc.title.p">
- <xsl:choose>
- <xsl:when test="$make.clean.html != 0">
- <div class="toc-title">
- <xsl:call-template name="gentext">
- <xsl:with-param name="key">TableofContents</xsl:with-param>
- </xsl:call-template>
- </div>
- </xsl:when>
- <xsl:otherwise>
- <p>
- <b>
- <xsl:call-template name="gentext">
- <xsl:with-param name="key">TableofContents</xsl:with-param>
- </xsl:call-template>
- </b>
- </p>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:if>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="$manual.toc != ''">
- <xsl:variable name="id">
- <xsl:call-template name="object.id"/>
- </xsl:variable>
- <xsl:variable name="toc" select="document($manual.toc, .)"/>
- <xsl:variable name="tocentry" select="$toc//tocentry[@linkend=$id]"/>
- <xsl:if test="$tocentry and $tocentry/*">
- <div class="toc">
- <xsl:copy-of select="$toc.title"/>
- <nav epub:type="toc">
- <xsl:element name="{$toc.list.type}">
- <xsl:call-template name="manual-toc">
- <xsl:with-param name="tocentry" select="$tocentry/*[1]"/>
- </xsl:call-template>
- </xsl:element>
- </nav>
- </div>
- </xsl:if>
- </xsl:when>
- <xsl:otherwise>
- <xsl:choose>
- <xsl:when test="$qanda.in.toc != 0">
- <div class="toc">
- <xsl:copy-of select="$toc.title"/>
- <nav epub:type="toc">
- <xsl:element name="{$toc.list.type}">
- <xsl:if test="$nodes.plus">
- <xsl:apply-templates select="$nodes.plus" mode="toc">
- <xsl:with-param name="toc-context" select="$toc-context"/>
- </xsl:apply-templates>
- </xsl:if>
- </xsl:element>
- </nav>
- </div>
- </xsl:when>
- <xsl:otherwise>
- <div class="toc">
- <xsl:copy-of select="$toc.title"/>
- <nav epub:type="toc">
- <xsl:element name="{$toc.list.type}">
- <xsl:if test="$nodes">
- <xsl:apply-templates select="$nodes" mode="toc">
- <xsl:with-param name="toc-context" select="$toc-context"/>
- </xsl:apply-templates>
- </xsl:if>
- </xsl:element>
- </nav>
- </div>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template name="list.of.titles">
- <xsl:param name="toc-context" select="."/>
- <xsl:param name="titles" select="'table'"/>
- <xsl:param name="nodes" select=".//table"/>
- <xsl:variable name="epub.type">
- <xsl:choose>
- <xsl:when test="$titles='table'">lot</xsl:when>
- <xsl:when test="$titles='figure'">loi</xsl:when>
- <xsl:when test="$titles='equation'">loi</xsl:when>
- <xsl:when test="$titles='example'">loi</xsl:when>
- <xsl:when test="$titles='procedure'">loi</xsl:when>
- <xsl:otherwise>loi</xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:if test="$nodes">
- <div class="list-of-{$titles}s">
- <nav epub:type="{$epub.type}">
- <h4 class="toc-title">
- <xsl:call-template name="gentext">
- <xsl:with-param name="key">
- <xsl:choose>
- <xsl:when test="$titles='table'">ListofTables</xsl:when>
- <xsl:when test="$titles='figure'">ListofFigures</xsl:when>
- <xsl:when test="$titles='equation'">ListofEquations</xsl:when>
- <xsl:when test="$titles='example'">ListofExamples</xsl:when>
- <xsl:when test="$titles='procedure'">ListofProcedures</xsl:when>
- <xsl:otherwise>ListofUnknown</xsl:otherwise>
- </xsl:choose>
- </xsl:with-param>
- </xsl:call-template>
- </h4>
- <xsl:element name="{$toc.list.type}">
- <xsl:apply-templates select="$nodes" mode="toc">
- <xsl:with-param name="toc-context" select="$toc-context"/>
- </xsl:apply-templates>
- </xsl:element>
- </nav>
- </div>
- </xsl:if>
- </xsl:template>
- <!-- EPUB3: add hidden="" for sections below toc.section.depth -->
- <xsl:template name="subtoc">
- <xsl:param name="toc-context" select="."/>
- <xsl:param name="nodes" select="NOT-AN-ELEMENT"/>
- <xsl:variable name="nodes.plus" select="$nodes | qandaset"/>
- <xsl:variable name="depth">
- <xsl:choose>
- <xsl:when test="local-name(.) = 'section'">
- <xsl:value-of select="count(ancestor::section) + 1"/>
- </xsl:when>
- <xsl:when test="local-name(.) = 'sect1'">1</xsl:when>
- <xsl:when test="local-name(.) = 'sect2'">2</xsl:when>
- <xsl:when test="local-name(.) = 'sect3'">3</xsl:when>
- <xsl:when test="local-name(.) = 'sect4'">4</xsl:when>
- <xsl:when test="local-name(.) = 'sect5'">5</xsl:when>
- <xsl:when test="local-name(.) = 'refsect1'">1</xsl:when>
- <xsl:when test="local-name(.) = 'refsect2'">2</xsl:when>
- <xsl:when test="local-name(.) = 'refsect3'">3</xsl:when>
- <xsl:when test="local-name(.) = 'simplesect'">
- <!-- sigh... -->
- <xsl:choose>
- <xsl:when test="local-name(..) = 'section'">
- <xsl:value-of select="count(ancestor::section)"/>
- </xsl:when>
- <xsl:when test="local-name(..) = 'sect1'">2</xsl:when>
- <xsl:when test="local-name(..) = 'sect2'">3</xsl:when>
- <xsl:when test="local-name(..) = 'sect3'">4</xsl:when>
- <xsl:when test="local-name(..) = 'sect4'">5</xsl:when>
- <xsl:when test="local-name(..) = 'sect5'">6</xsl:when>
- <xsl:when test="local-name(..) = 'refsect1'">2</xsl:when>
- <xsl:when test="local-name(..) = 'refsect2'">3</xsl:when>
- <xsl:when test="local-name(..) = 'refsect3'">4</xsl:when>
- <xsl:otherwise>1</xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:otherwise>0</xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
- <xsl:variable name="subtoc">
- <xsl:element name="{$toc.list.type}">
- <xsl:choose>
- <xsl:when test="$toc.listitem.type = 'li'
- and $toc.section.depth > $depth and
- ( ($qanda.in.toc = 0 and count($nodes)>0) or
- ($qanda.in.toc != 0 and count($nodes.plus)>0) )
- and $toc.max.depth > $depth.from.context">
- <!-- No @hidden attribute -->
- </xsl:when>
- <xsl:otherwise>
- <!-- Add empty @hidden attribute if too deep -->
- <xsl:attribute name="hidden"></xsl:attribute>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:choose>
- <xsl:when test="$qanda.in.toc != 0">
- <xsl:apply-templates mode="toc" select="$nodes.plus">
- <xsl:with-param name="toc-context" select="$toc-context"/>
- </xsl:apply-templates>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates mode="toc" select="$nodes">
- <xsl:with-param name="toc-context" select="$toc-context"/>
- </xsl:apply-templates>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:element>
- </xsl:variable>
- <xsl:variable name="subtoc.list">
- <xsl:choose>
- <xsl:when test="$toc.dd.type = ''">
- <xsl:copy-of select="$subtoc"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:element name="{$toc.dd.type}">
- <xsl:copy-of select="$subtoc"/>
- </xsl:element>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:element name="{$toc.listitem.type}">
- <xsl:call-template name="toc.line">
- <xsl:with-param name="toc-context" select="$toc-context"/>
- </xsl:call-template>
- <xsl:if test="$toc.listitem.type = 'li'
- and
- ( ($qanda.in.toc = 0 and count($nodes)>0) or
- ($qanda.in.toc != 0 and count($nodes.plus)>0) ) ">
- <xsl:copy-of select="$subtoc.list"/>
- </xsl:if>
- </xsl:element>
- </xsl:template>
- <!-- Inserted when a title is blank to avoid epubcheck error -->
- <xsl:param name="toc.entry.default.text"> </xsl:param>
- <!-- EPUB3: either <a> or <span>, but not both -->
- <xsl:template name="toc.line">
- <xsl:param name="toc-context" select="."/>
- <xsl:param name="depth" select="1"/>
- <xsl:param name="depth.from.context" select="8"/>
- <xsl:variable name="title">
- <xsl:apply-templates select="." mode="title.markup"/>
- </xsl:variable>
- <a>
- <xsl:attribute name="href">
- <xsl:call-template name="href.target">
- <xsl:with-param name="context" select="$toc-context"/>
- <xsl:with-param name="toc-context" select="$toc-context"/>
- </xsl:call-template>
- </xsl:attribute>
-
- <!-- * if $autotoc.label.in.hyperlink is non-zero, then output the label -->
- <!-- * as part of the hyperlinked title -->
- <xsl:if test="not($autotoc.label.in.hyperlink = 0)">
- <xsl:variable name="label">
- <xsl:apply-templates select="." mode="label.markup"/>
- </xsl:variable>
- <xsl:copy-of select="$label"/>
- <xsl:if test="$label != ''">
- <xsl:value-of select="$autotoc.label.separator"/>
- </xsl:if>
- </xsl:if>
- <xsl:choose>
- <xsl:when test="string-length(normalize-space($title)) != 0">
- <xsl:copy-of select="$title"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$toc.entry.default.text"/>
- </xsl:otherwise>
- </xsl:choose>
- </a>
- </xsl:template>
- <!-- Make sure all text is inside the <a> element for epub3 -->
- <xsl:template match="figure|table|example|equation|procedure" mode="toc">
- <xsl:param name="toc-context" select="."/>
- <xsl:element name="{$toc.listitem.type}">
- <a>
- <xsl:attribute name="href">
- <xsl:call-template name="href.target">
- <xsl:with-param name="toc-context" select="$toc-context"/>
- </xsl:call-template>
- </xsl:attribute>
- <xsl:variable name="label">
- <xsl:apply-templates select="." mode="label.markup"/>
- </xsl:variable>
- <xsl:copy-of select="$label"/>
- <xsl:if test="$label != ''">
- <xsl:value-of select="$autotoc.label.separator"/>
- </xsl:if>
- <xsl:apply-templates select="." mode="titleabbrev.markup"/>
- </a>
- </xsl:element>
- </xsl:template>
- <!-- Remove spans from refentry TOC lines for epub3check -->
- <xsl:template match="refentry" mode="toc">
- <xsl:param name="toc-context" select="."/>
- <xsl:variable name="refmeta" select=".//refmeta"/>
- <xsl:variable name="refentrytitle" select="$refmeta//refentrytitle"/>
- <xsl:variable name="refnamediv" select=".//refnamediv"/>
- <xsl:variable name="refname" select="$refnamediv//refname"/>
- <xsl:variable name="refdesc" select="$refnamediv//refdescriptor"/>
- <xsl:variable name="title">
- <xsl:choose>
- <xsl:when test="$refentrytitle">
- <xsl:apply-templates select="$refentrytitle[1]" mode="titleabbrev.markup"/>
- </xsl:when>
- <xsl:when test="$refdesc">
- <xsl:apply-templates select="$refdesc" mode="titleabbrev.markup"/>
- </xsl:when>
- <xsl:when test="$refname">
- <xsl:apply-templates select="$refname[1]" mode="titleabbrev.markup"/>
- </xsl:when>
- </xsl:choose>
- </xsl:variable>
- <xsl:element name="{$toc.listitem.type}" namespace="http://www.w3.org/1999/xhtml">
- <a>
- <xsl:attribute name="href">
- <xsl:call-template name="href.target">
- <xsl:with-param name="toc-context" select="$toc-context"/>
- </xsl:call-template>
- </xsl:attribute>
- <xsl:copy-of select="$title"/>
- <xsl:if test="$annotate.toc != 0">
- <!-- * DocBook 5 says inlinemediaobject (among other things) -->
- <!-- * is allowed in refpurpose; so we need to run -->
- <!-- * apply-templates on refpurpose here, instead of value-of -->
- <!-- Set allow-anchors=0 to avoid indexterms and other links -->
- <xsl:text> - </xsl:text>
- <xsl:apply-templates select="refnamediv/refpurpose" mode="no.anchor.mode"/>
- </xsl:if>
- </a>
- </xsl:element>
- </xsl:template>
- <!-- Copy these here so relative document() open gets the correct css source -->
- <xsl:template name="generate.default.css.file">
- <xsl:if test="$make.clean.html != 0 and
- $generate.css.header = 0 and
- $docbook.css.source != ''">
- <!-- Select default file relative to stylesheet -->
- <xsl:variable name="css.node" select="document($docbook.css.source)/*[1]"/>
- <xsl:call-template name="generate.css.file">
- <xsl:with-param name="src" select="$docbook.css.source"/>
- <xsl:with-param name="css.node" select="$css.node"/>
- </xsl:call-template>
- </xsl:if>
- </xsl:template>
- <xsl:template name="generate.custom.css.file">
- <xsl:if test="$custom.css.source != '' and
- $generate.css.header = 0">
- <!-- Select custom file relative to document -->
- <xsl:variable name="css.node" select="document($custom.css.source,.)/*[1]"/>
- <xsl:call-template name="generate.css.file">
- <xsl:with-param name="src" select="$custom.css.source"/>
- <xsl:with-param name="css.node" select="$css.node"/>
- </xsl:call-template>
- </xsl:if>
- </xsl:template>
- </xsl:stylesheet>
|