I should have mentioned also that this is for the older epub format. I have not 
yet looked at epub3, so I don't know if this translates.

-----Original Message-----
From: Jason Zech [mailto:[email protected]] 
Sent: Monday, February 04, 2013 3:13 PM
To: Richard Hamilton
Cc: DocBook Apps
Subject: RE: [docbook-apps] TOC on kindle

I'll put up the customizations, if anyone finds them helpful. And a sample 
output.

I worked on 3 templates, but only 1 gets heavy customization. 

In xhtml/autotoc.xsl: I removed the list-related <xsl:element> tags from the 
templates "make.toc" and "subtoc". 

The bigger customization to add the p and span tags I use is in the "toc.line" 
template. Due to our design needs, I like to be able to style chapter/part 
labels differently from chapter/part titles from time to time, so there are 
spans added inside my p tags as well. All class names are generated based on 
the element it is related to. 

There is probably more fiddly stuff in this than most people need, including 
references to some parameters I've created for my designer to use, but I don't 
want to simplify and give you a template that doesn't work as expected. If you 
don't care about the spans, you can probably simplify my template quite a bit.

Here's a sample output from the bk-toc.html in my epub:

<?xml version="1.0" encoding="utf-8"?><html 
xmlns="http://www.w3.org/1999/xhtml"; version="-//W3C//DTD XHTML 1.1//EN">
   <head profile="">
      <title>Book Title</title>
      <link rel="stylesheet" type="text/css" href="css/ebook.css"/>
      <meta name="generator" content="DocBook XSL Stylesheets V1.77.1"/>
      <meta name="description" content="Description to come"/>
   </head>
   <body>
      <h1>Book Title</h1>
      <div class="toc">
         <h3 class="title">Contents</h3>
         <p class="toc-preface-line">
            <span class="toc-preface-label"/>
            <span class="toc-preface-title">
               <a href="pr01.html" shape="rect">The Title of the Preface</a>
            </span>
         </p>
         <p class="toc-part-line">
            <span class="toc-part-label">Part 1   </span>
            <span class="toc-part-title">
               <a href="pt01.html" shape="rect">The Title of Part One</a>
            </span>
         </p>
         <p class="toc-chapter-line">
            <span class="toc-chapter-label">Chapter 1     </span>
            <span class="toc-chapter-title">
               <a href="ch01.html" shape="rect">The Title of Chapter One</a>
            </span>
         </p>
         <p class="toc-chapter-line">
            <span class="toc-chapter-label">Chapter 2     </span>
            <span class="toc-chapter-title">
               <a href="ch02.html" shape="rect">The Title of Chapter Two</a>
            </span>
         </p>
         <p class="toc-chapter-line">
            <span class="toc-chapter-label">Chapter 3     </span>
            <span class="toc-chapter-title">
               <a href="ch03.html" shape="rect">The Title of Chapter Three</a>
            </span>
         </p>
         <p class="toc-part-line">
            <span class="toc-part-label">Part 2   </span>
            <span class="toc-part-title">
               <a href="pt02.html" shape="rect">The Title of Part Two</a>
            </span>
         </p>
         <p class="toc-chapter-line">
            <span class="toc-chapter-label">Chapter 4     </span>
            <span class="toc-chapter-title">
               <a href="ch04.html" shape="rect">The Title of Chapter Four</a>
            </span>
         </p>
         <p class="toc-chapter-line">
            <span class="toc-chapter-label">Chapter 5     </span>
            <span class="toc-chapter-title">
               <a href="ch05.html" shape="rect">The Title of Chapter Five</a>
            </span>
         </p>
         <p class="toc-appendix-line">
            <span class="toc-appendix-label"/>
            <span class="toc-appendix-title">
               <a href="ata.html" shape="rect">Other Books Published by Me</a>
            </span>
         </p>
      </div>
   </body>
</html>

And here is the third template, the one with significant customization:

<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"/>
        
        <p>
            <xsl:attribute name="class">
                <xsl:text>toc-</xsl:text>
                <xsl:value-of select="local-name(.)"/>
                <xsl:text>-line</xsl:text>
            </xsl:attribute>
            
            <xsl:if test="$toc.labels != 0">
                <span>
                    <!--      <xsl:attribute name="class"><xsl:value-of 
select="local-name(.)"/></xsl:attribute>-->
                    <xsl:attribute name="class">
                        <xsl:text>toc-</xsl:text>
                        <xsl:value-of select="local-name(.)"/>
                        <xsl:text>-label</xsl:text>
                    </xsl:attribute>
                    <!-- added -->
                    
                    <!-- * if $autotoc.label.in.hyperlink is zero, then output 
the label -->
                    <!-- * before the hyperlinked title (as the DSSSL 
stylesheet does) -->
                    <xsl:if test="$autotoc.label.in.hyperlink = 0">
                        <xsl:variable name="label">
                            <xsl:apply-templates select="." 
mode="label.markup"/>
                        </xsl:variable>
                        <!-- if you are processing part title, put in the part 
label and 2 nbsp before the number -->
                        <xsl:if test="self::d:part">
                            <xsl:copy-of select="$TOCpartLabel"/>
                            <xsl:copy-of select="$label"/>
                        </xsl:if>
                        <!-- the following "if" section is new: processes 
chapter titles, adds the custom label and spacing; if no label adds extra 2 
nbsp before single digit numbers to make them line up on the page   -->
                        <xsl:if test="(self::d:chapter or self::d:article)">
                            <xsl:choose>
                                <xsl:when test="$TOCchapterLabel = ''">
                                    <xsl:choose>
                                        <xsl:when test="$label &lt;= 9">
                                            <!-- when single digit with no 
label, add 2 nbsp before number to even out alignment with 2 digit numbers -->
                                            <xsl:text>&#160;&#160;</xsl:text>
                                            <xsl:copy-of select="$label"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:copy-of select="$label"/>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:choose>
                                        <xsl:when test="$label &lt;= 9">
                                            <!-- when single digit with label, 
add 2 nbsp after number to even out alignment of titles with 2 digit chapter 
titles -->
                                            <xsl:value-of 
select="$TOCchapterLabel"/>
                                            <xsl:copy-of select="$label"/>
                                            <xsl:text>&#160;&#160;</xsl:text>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:value-of 
select="$TOCchapterLabel"/>
                                            <xsl:copy-of select="$label"/>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:if>
                        <xsl:if test="$label != ''">
                            <xsl:value-of select="$autotoc.label.separator"/>
                        </xsl:if>
                    </xsl:if>
                </span>
            </xsl:if>
            <!-- added to close span after label, opened a new one on title, 
added custom class generation for this second span -->
            <span>
                <xsl:attribute name="class">
                    <xsl:text>toc-</xsl:text>
                    <xsl:value-of select="local-name(.)"/>
                    <xsl:text>-title</xsl:text>
                </xsl:attribute>
                <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:apply-templates select="." mode="titleabbrev.markup"/>
                </a>
            </span>
            

        </p>
        
    </xsl:template>





-----Original Message-----
From: Richard Hamilton [mailto:[email protected]] 
Sent: Monday, February 04, 2013 1:12 PM
To: Jason Zech
Cc: DocBook Apps
Subject: Re: [docbook-apps] TOC on kindle

Hi Jason,

I think that may be where I end up. Do you have any examples of TOCs you've 
built that you can share with the group?

Best Regards,
Dick
-------
XML Press
XML for Technical Communicators
http://xmlpress.net
[email protected]



On Feb 4, 2013, at 10:07 AM, Jason Zech wrote:

> I haven't started using EPUB3 stylesheets yet, but for my epub2 and kindle 
> work, I finally customized the stylesheets to produce my TOC lines as p tags 
> with useful class names that I can control in the CSS. Neither of the built 
> in list-options for TOC seemed to work well enough for my purposes, 
> especially when going into Kindlegen. You could try that route. Requires more 
> CSS work, but results in much better control. 
> 
> -----Original Message-----
> From: Richard Hamilton [mailto:[email protected]] 
> Sent: Sunday, February 03, 2013 5:22 PM
> To: DocBook Apps
> Subject: [docbook-apps] TOC on kindle
> 
> I've been building books with the ePub3 style sheets, then using kindlegen to 
> convert them to .mobi.
> 
> It works pretty well for most things, however, the TOC is giving me several 
> problems.
> 
> 1) At least in the emulator, it seems like only the Kindle Paperwhite honors 
> the hidden attribute on <ol>. The result is that even if toc.section.depth is 
> set to 0 and toc.max.depth set to 1, most Kindles show a complete toc (I'm 
> talking about the xhtml toc here, not the .ncx toc).
> 
> 2) Some kindles, e.g., first generation and the iPad and iPhone apps (again 
> this is seen in the emulator, but I think the emulator is pretty good these 
> days), interpret the <ol> elements literally, which means that you get 
> numbering that does not appear in other instances or in ePub readers. And, 
> since the numbering encompasses prefaces, appendixes, colophons, etc. the 
> numbers often bear no relation to any actual chapter numbers.
> 
> So, my question is whether there are ways to work around these problems to 
> make the Kindle versions behave a bit more sensibly?
> 
> Best Regards,
> Dick Hamilton
> -------
> XML Press
> XML for Technical Communicators
> http://xmlpress.net
> [email protected]
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to