Cocoon epub Compiler

Synopsis
This is an XSLT stylesheet for use with Apache Cocoon which generates epub formatted ebooks.

The stylesheet is based very strongly on the epub worked example at http://www.hxa.name/articles/content/epub-guide_hxa7241_2007.html and the cocoon zip serializer example at http://cocoon.apache.org/2.0/userdocs/serializers/ziparchive-serializer.html
 * professional seo
 * website optimizer
 * web design service

User commentary
Please sign all comments. (please leave the above note about signing comments, and add signed comments here below it)

System requirements
Assumes that you're already using Apache Cocoon.

Source code and licensing
Source code is included at the bottom of this article

Language(s)
XSLT

Documentation
None

Tech support
None

 

 



&#x100;&#x112;&#x12A;&#x14C;&#x16A;&#x101;&#x113;&#x12B;&#x14D;&#x16B;&#x00A0; AEIOUaeiou   

 

    <xsl:if test="not(preceding::tei:figure[tei:graphic/@url = $entity])"> <zip:entry name="{concat('etexts/',                              /tei:TEI/@xml:id,                               '/',                                substring-before($entity,'.'),                               '(t100).',                               substring-after($entity,'.'))}" src="{concat('cocoon:/etexts/',                             /tei:TEI/@xml:id,                              '/',                              substring-before($entity,'.'),                              '(t100).',                              substring-after($entity,'.'))}" /> <zip:entry name="{concat('etexts/',                              /tei:TEI/@xml:id,                               '/',                                substring-before($entity,'.'),                               '(t150).',                               substring-after($entity,'.'))}" src="{concat('cocoon:/etexts/',                             /tei:TEI/@xml:id,                              '/',                              substring-before($entity,'.'),                              '(t150).',                              substring-after($entity,'.'))}" /> <zip:entry name="{concat('etexts/',                              /tei:TEI/@xml:id,                               '/',                                substring-before($entity,'.'),                               '(h280).',                               substring-after($entity,'.'))}" src="{concat('cocoon:/etexts/',                             /tei:TEI/@xml:id,                              '/',                               substring-before($entity,'.'),                              '(h280).',                              substring-after($entity,'.'))}" /> </xsl:if> </xsl:when> <xsl:otherwise> <zip:entry name="tm/scholarly/{@nzetc:id}.html" src="cocoon:/tm/scholarly/{@nzetc:id}.xhtml11" /> </xsl:otherwise> </xsl:choose> </xsl:for-each> <zip:entry name="tm/main.css" src="cocoon:/tm/main.css" /> <zip:entry name="tm/print.css" src="cocoon:/tm/print.css" /> <zip:entry name="tm/referer.js" src="cocoon:/tm/referrer.js" />

<zip:entry name="META-INF/container.xml" serializer="xml"> <container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container"> <rootfile full-path="content.opf" media-type="application/oebps-package+xml"/> </zip:entry> <zip:entry name="content.opf" serializer="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:value-of select="translate(normalize-space(//tei:title),$accented,$unaccented)"/></dc:title> <dc:language xsi:type="dcterms:RFC3066"><xsl:value-of select="normalize-space(/@xml:lang)"/></dc:language> <dc:identifier id="dcidid" opf:scheme="URI">http://www.nzetc.org/tm/scholarly/tei-<xsl:value-of select="/tei:TEI/@xml:id"/>.html</dc:identifier> <xsl:for-each select="//tei:textClass/tei:keywords//tei:rs"> <dc:subject><xsl:value-of select="normalize-space(.)"/></dc:subject> </xsl:for-each>

<xsl:for-each select="//tei:author[generate-id = generate-id(key('authors',normalize-space(.))[1])]"> <dc:creator><xsl:value-of select="normalize-space(.)"/></dc:creator> </xsl:for-each> <dc:publisher>New Zealand Electronic Text Centre</dc:publisher> <dc:date xsi:type="dcterms:W3CDTF">2007-12-28</dc:date> <dc:rights>Creative Commons</dc:rights> <item id="main.css" href="tm/main.css" media-type="text/css" /> <item id="print.css" href="tm/print.css" media-type="text/css" /> <item id="referer.js" href="tm/referer.js" media-type="text/javascript" /> <item id="head" href="tm/scholarly/tei-{/tei:TEI/@xml:id}.html" media-type="application/xhtml+xml" /> <item id="metadata" href="tm/scholarly/metadata-{/tei:TEI/@xml:id}.html" media-type="application/xhtml+xml" />

<xsl:for-each select="$pages"> <xsl:choose> <xsl:when test="self::tei:figure">  <xsl:if test="not(preceding::tei:figure[tei:graphic/@url = $entity])">

 <xsl:choose> <xsl:when test="contains(tei:graphic/@url,'.gif')">image/gif</xsl:when> <xsl:otherwise>image/jpeg</xsl:otherwise> </xsl:choose> </xsl:variable> <item id="image-h280-{@xml:id}" href="{concat('etexts/',                               /tei:TEI/@xml:id,                                '/',                                substring-before(tei:graphic/@url,'.'),                                '(h280).',                                substring-after(tei:graphic/@url,'.'))}" media-type="{$mimetype}" /> <item id="image-t100-{@xml:id}" href="{concat('etexts/',                               /tei:TEI/@xml:id,                                '/',                                substring-before(tei:graphic/@url,'.'),                                '(t100).',                                substring-after(tei:graphic/@url,'.'))}" media-type="{$mimetype}" /> <item id="image-t150-{@xml:id}" href="{concat('etexts/',                               /tei:TEI/@xml:id,                                '/',                                substring-before(tei:graphic/@url,'.'),                                '(t150).',                                substring-after(tei:graphic/@url,'.'))}" media-type="{$mimetype}" />

</xsl:if> </xsl:when> <xsl:otherwise> <item id="page-{@xml:id}" href="tm/scholarly/{@nzetc:id}.html" media-type="application/xhtml+xml" /> </xsl:otherwise> </xsl:choose> </xsl:for-each>

<item id="ncx"     href="toc.ncx" media-type="application/x-dtbncx+xml" /> <xsl:for-each select="$pages[not(self::tei:figure)]"> <itemref idref="page-{@xml:id}" /> </xsl:for-each>

<reference type="colophon" title="Colophon" href="tm/scholarly/metadata-{tei:TEI/@xml:id}.html" /> <reference type="text" title="Text" href="tm/scholarly/tei-{/tei:TEI/@xml:id}.html" /> <xsl:for-each select="$pages[not(self::tei:figure)]"> <reference type="text" title="{normalize-space(./tei:head)}" href="tm/scholarly/{@nzetc:id}.html" /> </xsl:for-each> </zip:entry> <zip:entry name="toc.ncx" serializer="xml"> <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">

<meta name="dtb:uid" content="http://www.nzetc.org/tm/scholarly/tei-{/tei:TEI/@xml:id}.html"/> <meta name="dtb:totalPageCount" content="{count(//tei:pb)}"/> <meta name="dtb:maxPageNumber" content="{//tei:pb[@n][position=last]}"/>

<docTitle> <xsl:value-of select="translate(normalize-space(//tei:title),$accented,$unaccented)"/> </docTitle>

<navMap> <navPoint id="navPoint-1" playOrder="1"> <navLabel> digital title page and colophon </navLabel> <content src="tm/scholarly/metadata-{tei:TEI/@xml:id}.html"/> </navPoint> <xsl:for-each select="$pages[not(self::tei:figure)]"> <navPoint id="navPoint-{@xml:id}" playOrder="{position+1}"> <navLabel> <xsl:choose> <xsl:when test="normalize-space(.//tei:head)"> <xsl:value-of select="normalize-space(.//tei:head)"/> </xsl:when> <xsl:when test="normalize-space(@n)"> <xsl:text>[</xsl:text><xsl:value-of select="normalize-space(@n)"/><xsl:text>]</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>[untitled]</xsl:text> </xsl:otherwise> </xsl:choose> </navLabel> <content src="tm/scholarly/{@nzetc:id}.html"/> </navPoint> </xsl:for-each> </navMap> </zip:entry> </zip:archive> </xsl:template>

</xsl:stylesheet>