Stylesheet
tei-to-epub.xsl
Documentation
Description
TEI stylesheet for making ePub output. A lot learnt from
http://www.hxa.name/articles/content/epub-guide_hxa7241_2007.html and
the stylesheets of the NZETC.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author: See AUTHORS
Id: $Id: tei-to-epub.xsl 7897 2010-07-24 18:05:22Z rahtz $
Copyright: 2008, TEI Consortium
Imported modules
Imported from
Stylesheet version
2.0
Template
stdfooter
Template
generateLicence
Template
generateLanguage
Template
generateSubject
Template
generatePublisher
Template
generateID
Template
includeCSS
Template
/
Template
processTEI
Documentation
Description [epub] Override of top-level template. This does most of
the work: performing the normal transformation, fixing the links to graphics files so that they are
all relative, creating the extra output files, etc
Namespace
No namespace
Used by
References
Supersedes
Import precedence
4
Source
<xsl:template name= "processTEI" >
<xsl:variable name= "stage1" >
<xsl:apply-templates mode= "fixgraphics" />
</xsl:variable>
<xsl:for-each select= "$stage1" >
<xsl:apply-templates mode= "split" />
<xsl:for-each select= "*" >
<xsl:variable name= "TOC" >
<TOC xmlns= "http://www.w3.org/1999/xhtml" >
<xsl:call-template name= "mainTOC" />
</TOC>
</xsl:variable>
<!--
<xsl:result-document href="/tmp/TOC">
<xsl:copy-of select="$TOC"/>
</xsl:result-document>
-->
<xsl:if test= "$debug='true'" >
<xsl:message > write file OEBPS/stylesheet.css </xsl:message>
</xsl:if>
<xsl:result-document method= "text" href= "{concat($directory,'OEBPS/stylesheet.css')}" >
<xsl:if test= "$debug='true'" >
<xsl:message > reading file
<xsl:value-of select= "$cssFile" />
</xsl:message>
</xsl:if>
<xsl:for-each select= "tokenize(unparsed-text($cssFile), '\r?\n')" >
<xsl:call-template name= "purgeCSS" />
</xsl:for-each>
<xsl:if test= "$odd='true'" >
<xsl:if test= "$debug='true'" >
<xsl:message > reading file
<xsl:value-of select= "$cssODDFile" />
</xsl:message>
</xsl:if>
<xsl:for-each select= "tokenize(unparsed-text($cssODDFile), '\r?\n')" >
<xsl:call-template name= "purgeCSS" />
</xsl:for-each>
</xsl:if>
</xsl:result-document>
<xsl:if test= "$debug='true'" >
<xsl:message > write file OEBPS/print.css </xsl:message>
</xsl:if>
<xsl:result-document method= "text" href= "{concat($directory,'OEBPS/print.css')}" >
<xsl:if test= "$debug='true'" >
<xsl:message > reading file
<xsl:value-of select= "$cssPrintFile" />
</xsl:message>
</xsl:if>
<xsl:for-each select= "tokenize(unparsed-text($cssPrintFile), '\r?\n')" >
<xsl:call-template name= "purgeCSS" />
</xsl:for-each>
</xsl:result-document>
<xsl:if test= "$debug='true'" >
<xsl:message > write file mimetype </xsl:message>
</xsl:if>
<xsl:result-document method= "text" href= "{concat($directory,'mimetype')}" >
<xsl:text > application/epub+zip </xsl:text>
</xsl:result-document>
<xsl:if test= "$debug='true'" >
<xsl:message > write file META-INF/container.xml </xsl:message>
</xsl:if>
<xsl:result-document method= "xml" href= "{concat($directory,'META-INF/container.xml')}" >
<container xmlns= "urn:oasis:names:tc:opendocument:xmlns:container" version= "1.0" >
<rootfiles >
<rootfile full-path= "OEBPS/content.opf" media-type= "application/oebps-package+xml" />
</rootfiles>
</container>
</xsl:result-document>
<xsl:if test= "$debug='true'" >
<xsl:message > write file OEBPS/content.opf </xsl:message>
</xsl:if>
<xsl:result-document href= "{concat($directory,'OEBPS/content.opf')}" method= "xml" >
<package xmlns= "http://www.idpf.org/2007/opf" unique-identifier= "dcidid" version= "2.0" >
<metadata xmlns:dc= "http://purl.org/dc/elements/1.1/" xmlns:dcterms= "http://purl.org/dc/terms/" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:opf= "http://www.idpf.org/2007/opf" >
<dc:title >
<xsl:call-template name= "generateSimpleTitle" />
</dc:title>
<dc:language xsi:type= "dcterms:RFC3066" >
<xsl:call-template name= "generateLanguage" />
</dc:language>
<dc:subject >
<xsl:call-template name= "generateSubject" />
</dc:subject>
<dc:identifier id= "dcidid" opf:scheme= "URI" >
<xsl:call-template name= "generateID" />
</dc:identifier>
<dc:creator >
<xsl:call-template name= "generateAuthor" />
</dc:creator>
<dc:publisher >
<xsl:call-template name= "generatePublisher" />
</dc:publisher>
<dc:date xsi:type= "dcterms:W3CDTF" >
<xsl:call-template name= "generateDate" />
</dc:date>
<dc:rights >
<xsl:call-template name= "generateLicence" />
</dc:rights>
<xsl:if test= "not($coverimage='')" >
<meta name= "cover" content= "cover-image" />
</xsl:if>
</metadata>
<manifest >
<xsl:if test= "not($coverimage='')" >
<item href= "{$coverimage}" id= "cover-image" media-type= "image/jpeg" />
</xsl:if>
<item href= "stylesheet.css" id= "css" media-type= "text/css" />
<item href= "titlepage.html" id= "titlepage" media-type= "application/xhtml+xml" />
<item href= "titlepageback.html" id= "titlepageback" media-type= "application/xhtml+xml" />
<item id= "print.css" href= "print.css" media-type= "text/css" />
<item id= "apt" href= "page-template.xpgt" media-type= "application/adobe-page-template+xml" />
<item id= "start" href= "index.html" media-type= "application/xhtml+xml" />
<xsl:for-each select= "$TOC/html:TOC/html:ul/html:li" >
<xsl:if test= "html:a and not(starts-with(html:a/@href,'#'))" >
<item href= "{html:a[1]/@href}" media-type= "application/xhtml+xml" >
<xsl:attribute name= "id" >
<xsl:text > section </xsl:text>
<xsl:number count= "html:li" level= "any" />
</xsl:attribute>
</item>
</xsl:if>
<xsl:if test= "html:ul" >
<xsl:for-each select= "html:ul//html:li[not(contains(html:a/@href,'#'))]" >
<item href= "{html:a[1]/@href}" media-type= "application/xhtml+xml" >
<xsl:attribute name= "id" >
<xsl:text > section </xsl:text>
<xsl:number count= "html:li" level= "any" />
</xsl:attribute>
</item>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
<!-- images -->
<xsl:for-each select= "key('GRAPHICS',1)" >
<xsl:variable name= "ID" >
<xsl:number level= "any" />
</xsl:variable>
<xsl:variable name= "mimetype" >
<xsl:choose >
<xsl:when test= "contains(@url,'.gif')" > image/gif </xsl:when>
<xsl:when test= "contains(@url,'.png')" > image/png </xsl:when>
<xsl:otherwise > image/jpeg </xsl:otherwise>
</xsl:choose>
</xsl:variable>
<item href= "{@url}" id= "image-{$ID}" media-type= "{$mimetype}" />
</xsl:for-each>
<!-- page images -->
<xsl:for-each select= "key('PAGEIMAGES',1)" >
<xsl:variable name= "ID" >
<xsl:text > pb </xsl:text>
<xsl:number level= "any" />
</xsl:variable>
<xsl:variable name= "mimetype" >
<xsl:choose >
<xsl:when test= "contains(@url,'.gif')" > image/gif </xsl:when>
<xsl:when test= "contains(@url,'.png')" > image/png </xsl:when>
<xsl:otherwise > image/jpeg </xsl:otherwise>
</xsl:choose>
</xsl:variable>
<item href= "{@facs}" id= "image-{$ID}" media-type= "{$mimetype}" />
</xsl:for-each>
<item id= "ncx" href= "toc.ncx" media-type= "application/x-dtbncx+xml" />
</manifest>
<spine toc= "ncx" >
<itemref idref= "titlepage" />
<itemref idref= "start" />
<xsl:for-each select= "$TOC/html:TOC/html:ul/html:li" >
<xsl:if test= "html:a and not(starts-with(html:a/@href,'#'))" >
<itemref >
<xsl:attribute name= "idref" >
<xsl:text > section </xsl:text>
<xsl:number count= "html:li" level= "any" />
</xsl:attribute>
</itemref>
</xsl:if>
<xsl:if test= "html:ul" >
<xsl:for-each select= "html:ul//html:li[not(contains(html:a/@href,'#'))]" >
<itemref >
<xsl:attribute name= "idref" >
<xsl:text > section </xsl:text>
<xsl:number count= "html:li" level= "any" />
</xsl:attribute>
</itemref>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
<itemref idref= "titlepageback" />
</spine>
<guide >
<reference href= "titlepage.html" type= "cover" title= "Cover" />
<reference type= "text" title= "Start" href= "index.html" />
<xsl:for-each select= "$TOC/html:TOC/html:ul/html:li" >
<xsl:if test= "html:a" >
<reference type= "text" href= "{html:a[1]/@href}" >
<xsl:attribute name= "title" >
<xsl:value-of select= "normalize-space(html:a[1])" />
</xsl:attribute>
</reference>
</xsl:if>
<!--
<xsl:if test="html:ul">
<xsl:for-each select="html:ul//html:li[not(contains(html:a/@href,'#'))]">
<reference type="text" href="{html:a/@href}">
<xsl:attribute name="title">
<xsl:value-of select="normalize-space(html:a[1])"/>
</xsl:attribute>
</reference>
</xsl:for-each>
</xsl:if>
-->
</xsl:for-each>
<reference href= "titlepageback.html" type= "text" title= "About this book" />
</guide>
</package>
</xsl:result-document>
<xsl:if test= "$debug='true'" >
<xsl:message > write file OEBPS/titlepage.html </xsl:message>
</xsl:if>
<xsl:result-document href= "{concat($directory,'OEBPS/titlepage.html')}" method= "xml" >
<html xmlns= "http://www.w3.org/1999/xhtml" xml:lang= "en" >
<head >
<meta http-equiv= "Content-Type" content= "text/html; charset=UTF-8" />
<meta name= "calibre:cover" content= "true" />
<title > Title page </title>
<style type= "text/css" title= "override_css" >
@page {padding: 0pt; margin:0pt}
body { text-align: center; padding:0pt; margin: 0pt; }
</style>
</head>
<body >
<xsl:choose >
<xsl:when test= "$coverimage=''" >
<div style= "font-family: serif; height:860; font-size:36pt; border: bold red 1pt; text-align:center" >
<xsl:call-template name= "generateTitle" />
</div>
</xsl:when>
<xsl:otherwise >
<div >
<img width= "600" height= "860" alt= "cover picture" src= "{$coverimage}" />
</div>
</xsl:otherwise>
</xsl:choose>
</body>
</html>
</xsl:result-document>
<xsl:if test= "$debug='true'" >
<xsl:message > write file OEBPS/titlepageback.html </xsl:message>
</xsl:if>
<xsl:result-document href= "{concat($directory,'OEBPS/titlepageback.html')}" method= "xml" >
<html xmlns= "http://www.w3.org/1999/xhtml" xml:lang= "en" >
<head >
<meta http-equiv= "Content-Type" content= "text/html; charset=UTF-8" />
<title > About this book </title>
</head>
<body >
<div style= "text-align: left; font-size: smaller" >
<h2 > Information about this book </h2>
<xsl:for-each select= "/*/tei:teiHeader/tei:fileDesc" >
<xsl:apply-templates mode= "metadata" />
</xsl:for-each>
</div>
</body>
</html>
</xsl:result-document>
<xsl:if test= "$debug='true'" >
<xsl:message > write file OEBPS/toc.ncx </xsl:message>
</xsl:if>
<xsl:result-document href= "{concat($directory,'OEBPS/toc.ncx')}" method= "xml" >
<ncx xmlns= "http://www.daisy.org/z3986/2005/ncx/" version= "2005-1" >
<head >
<meta name= "dtb:uid" >
<xsl:attribute name= "content" >
<xsl:call-template name= "generateID" />
</xsl:attribute>
</meta>
<meta name= "dtb:totalPageCount" content= "0" />
<meta name= "dtb:maxPageNumber" content= "0" />
</head>
<docTitle >
<text >
<xsl:call-template name= "generateSimpleTitle" />
</text>
</docTitle>
<navMap >
<xsl:variable name= "navPoints" >
<navPoint >
<navLabel >
<text > Title Page and Contents </text>
</navLabel>
<content src= "index.html" />
</navPoint>
<xsl:for-each select= "$TOC/html:TOC/html:ul/html:li" >
<xsl:if test= "html:a and not(starts-with(html:a/@href,'#'))" >
<navPoint >
<navLabel >
<text >
<xsl:value-of select= "html:span[@class='headingNumber']" />
<xsl:value-of select= "normalize-space(html:a[1])" />
</text>
</navLabel>
<content src= "{html:a/@href}" />
</navPoint>
</xsl:if>
<!-- <xsl:if test="html:ul">
<xsl:for-each select="html:ul/html:li">
<xsl:variable name="pos">
<xsl:number level="any"/>
</xsl:variable>
<navPoint id="navPoint-{$pos+1}" playOrder="{$pos+1}">
<navLabel>
<text>
<xsl:value-of select="normalize-space(html:a[1])"/>
</text>
</navLabel>
<content src="{html:a/@href}"/>
</navPoint>
</xsl:for-each>
</xsl:if>
-->
</xsl:for-each>
<navPoint >
<navLabel >
<text > About this book </text>
</navLabel>
<content src= "titlepageback.html" />
</navPoint>
</xsl:variable>
<xsl:for-each select= "$navPoints/ncx:navPoint" >
<xsl:variable name= "pos" select= "position()" />
<navPoint id= "navPoint-{$pos}" playOrder= "{$pos}" >
<xsl:copy-of select= "*" />
</navPoint>
</xsl:for-each>
</navMap>
</ncx>
</xsl:result-document>
<xsl:if test= "$debug='true'" >
<xsl:message > write file OEBPS/page-template.xpgt </xsl:message>
</xsl:if>
<xsl:result-document method= "xml" href= "{concat($directory,'OEBPS/page-template.xpgt')}" >
<ade:template xmlns= "http://www.w3.org/1999/xhtml" xmlns:ade= "http://ns.adobe.com/2006/ade" xmlns:fo= "http://www.w3.org/1999/XSL/Format" >
<fo:layout-master-set >
<fo:simple-page-master master-name= "single_column" >
<fo:region-body margin-bottom= "3pt" margin-top= "0.5em" margin-left= "3pt" margin-right= "3pt" />
</fo:simple-page-master>
<fo:simple-page-master master-name= "single_column_head" >
<fo:region-before extent= "8.3em" />
<fo:region-body margin-bottom= "3pt" margin-top= "6em" margin-left= "3pt" margin-right= "3pt" />
</fo:simple-page-master>
<fo:simple-page-master master-name= "two_column" margin-bottom= "0.5em" margin-top= "0.5em" margin-left= "0.5em" margin-right= "0.5em" >
<fo:region-body column-count= "2" column-gap= "10pt" />
</fo:simple-page-master>
<fo:simple-page-master master-name= "two_column_head" margin-bottom= "0.5em" margin-left= "0.5em" margin-right= "0.5em" >
<fo:region-before extent= "8.3em" />
<fo:region-body column-count= "2" margin-top= "6em" column-gap= "10pt" />
</fo:simple-page-master>
<fo:simple-page-master master-name= "three_column" margin-bottom= "0.5em" margin-top= "0.5em" margin-left= "0.5em" margin-right= "0.5em" >
<fo:region-body column-count= "3" column-gap= "10pt" />
</fo:simple-page-master>
<fo:simple-page-master master-name= "three_column_head" margin-bottom= "0.5em" margin-top= "0.5em" margin-left= "0.5em" margin-right= "0.5em" >
<fo:region-before extent= "8.3em" />
<fo:region-body column-count= "3" margin-top= "6em" column-gap= "10pt" />
</fo:simple-page-master>
<fo:page-sequence-master >
<fo:repeatable-page-master-alternatives >
<fo:conditional-page-master-reference master-reference= "three_column_head" page-position= "first" ade:min-page-width= "80em" />
<fo:conditional-page-master-reference master-reference= "three_column" ade:min-page-width= "80em" />
<fo:conditional-page-master-reference master-reference= "two_column_head" page-position= "first" ade:min-page-width= "50em" />
<fo:conditional-page-master-reference master-reference= "two_column" ade:min-page-width= "50em" />
<fo:conditional-page-master-reference master-reference= "single_column_head" page-position= "first" />
<fo:conditional-page-master-reference master-reference= "single_column" />
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
<ade:style >
<ade:styling-rule selector= ".title_box" display= "adobe-other-region" adobe-region= "xsl-region-before" />
</ade:style>
</ade:template>
</xsl:result-document>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
Stylesheet location
../../../epub/tei-to-epub.xsl
Template
verbatim-lineBreak
Template
@*|text()|comment()|processing-instruction() fixgraphics
Documentation
Namespace
No namespace
Match
@*|text()|comment()|processing-instruction()
Mode
fixgraphics
Import precedence
4
Source
Stylesheet location
../../../epub/tei-to-epub.xsl
Template
* fixgraphics
Template
tei:pb[@facs]|tei:graphic fixgraphics
Template
purgeCSS
Documentation
Description [epub] Remove unwanted things from CSS
Namespace
No namespace
Used by
Import precedence
4
Source
<xsl:template name= "purgeCSS" >
<xsl:choose >
<xsl:when test= "contains(.,'line-height:')" />
<xsl:when test= "contains(.,'max-width:')" />
<xsl:when test= "contains(.,'height:')" />
<xsl:when test= "contains(.,'text-indent:')" />
<!--
<xsl:when test="contains(.,'clear:')"/>
<xsl:when test="contains(.,'padding')"/>
<xsl:when test="contains(.,'float:')"/>
<xsl:when test="contains(.,'font-size:')"/>
<xsl:when test="contains(.,'width:')"/>
<xsl:when test="contains(.,'margin')"/>
<xsl:when test="contains(.,'border')"/>
-->
<xsl:otherwise >
<xsl:value-of select= "." />
<xsl:text >
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Stylesheet location
../../../epub/tei-to-epub.xsl
Template
tei:div/tei:bibl
Template
tei:l
Template
addLangAtt
Template
tei:pb[@facs]
Template
tei:lb[@rend='space']
Template
tei:titleStmt metadata
Template
tei:editionStmt metadata
Template
tei:publicationStmt metadata
Template
tei:seriesStmt metadata
Template
tei:notesStmt metadata
Template
tei:sourceDesc metadata
Template
tei:respStmt metadata
Template
tei:extent metadata
Template
tei:authority metadata
Template
tei:publicationStmt/tei:address metadata
Template
tei:publicationStmt/tei:publisher metadata
Template
tei:distributor metadata
Template
tei:idno metadata
Template
tei:availability[not(@n) and preceding-sibling::tei:availability/@n] metadata
Template
tei:availability metadata
Template
tei:date metadata
Template
* metadata
Template
tei:seriesStmt/tei:p
Template
tei:distributor/tei:address
Template
tei:authority/tei:address
Template
tei:authority/tei:addLine
Template
tei:title[@type='uniform']
Template
tei:editionStmt/tei:p
Template
tei:editor
Template
tei:title[@type='main']
Template
tei:title[@type='alternative']
Parameter
doctypePublic
Parameter
doctypeSystem
Parameter
directory
Parameter
splitLevel
Parameter
STDOUT
Parameter
outputDir
Parameter
cssFile
Parameter
cssPrintFile
Parameter
cssODDFile
Parameter
topNavigationPanel
Parameter
bottomNavigationPanel
Parameter
autoToc
Parameter
autoHead
Parameter
tocDepth
Parameter
linkPanel
Parameter
institution
Parameter
subject
Parameter
uid
Parameter
publisher
Parameter
coverimage
Parameter
odd
Parameter
debug
Output
(default)
Key
GRAPHICS
Key
PAGEIMAGES