View Single Post
Old 07-25-2009, 04:52 AM   #12
swr2408018 will become famous soon enoughswr2408018 will become famous soon enoughswr2408018 will become famous soon enoughswr2408018 will become famous soon enoughswr2408018 will become famous soon enoughswr2408018 will become famous soon enough
Posts: 35
Karma: 501
Join Date: Jul 2007
Device: PRS-500
Code snippets for headers and footers with epub+adobe extensions

Here's as close as I could get:

1) Create template.xpgt with this content (adapted from the ADE "best practices" code--my selection code is a little simpler):

<ade:template xmlns=""


<!-- list of page master definitions -->
<fo:simple-page-master master-name="header_body_and_footer">
<fo:region-before extent="1.5em"/>
<fo:region-body margin-top="1.5em" margin-bottom="1.5em"/>
<fo:region-after extent="1.5em"/>

<!-- page master selection -->
<fo:repeatable-page-master-reference master-reference="header_body_and_footer"/>


<!-- dynamic styling rules -->
<ade:styling-rule selector=".header" display="adobe-other-region" adobe-region="xsl-region-before"/>
<ade:styling-rule selector=".footer" display="adobe-other-region" adobe-region="xsl-region-after"/>


2) Add the template to the manifest:

<item id="template" href="template.xpgt" media-type="application/adobe-page-template+xml" />

3) Link to the selector logic through CSS definitions in style.css:

p.header {
text-indent: 0;
text-align: center;
font-weight: bold;

p.footer {
text-indent: 0;
text-align: center;
font-weight: bold;

4) Invoke all this machinery with code in the xhtml file:

<p class="header">Jane Austen&mdash;Pride and Prejudice</p>
<p class="footer">Chapter 1</p>

<h1 style="page-break-before:auto" id="toc-anchor-Chapter-1">Chapter 1</h1>

<p>It is a truth universally acknowledged, that a single man in possession of a good fortune, must be in want of a wife.</p>


Here is what works:

a) All the pages in the book are created with reserved space at the top and bottom per region-before and region-after up in 1) above.

b) The first page of text generated from this code has the header and footer in those reserved spaces. Thanks to the layout in "em" terms, it all scales nicely at different reader size settings.

Here is what doesn't work:

c) No other pages will have the header and footer text. If I add the same header and footer declarations later in the text, the page output for that point in the text will also have the header and footer. However, it clearly isn't possible to scatter hundreds of these through the text to make sure that all pages end up with header and footer text!

As far as I can tell, this is exactly "by design". In the world of XSL-FO, a flow of text into any of the five regions is only intended to be presented on one page. The mechanism XSL-FO provides for recycling text from one page to the next is <fo:static-content .... />, either with fixed text, with text that contains pre-defined running values like page #, or with a marker that can be redefined at will by additional directives in the text ("running headers")

The ADE "best practices" docs and samples don't show how to add static-content elements to the XSL; these elements are supposed to occur in the scope of a <foage-sequence ... /> element . I've tried a number of variants for adding these elements to the template file, but most of them hung or crashed both ADE and the Sony reader software. If they ran at all, I didn't get the expected static text appearing in the header or footer space. I suspect that the XSL parser in ADE et al only supports a subset of XSL-FO.

I'm about ready to give up on this; my remaining hopes:

A) I haven't yet tried adding XSL-FO directly to the xhtml file to see if that works any better.
B) Someone with better understanding of XSL-FO may have other suggestions.
C) If anyone has seen an epub book with chapter headers, it should be easy to reverse engineer.

However, as pointed out earlier in this thread, the XSL-FO approach Adobe has provided runs against the grain of the standard. Since the best reason for switching from LRF to epub is to get something that will reliably deploy cross-platform, I'd hate to spend a lot of time ironing out the kinks here, only to have to replace them 6-12 months from now. So I'd appreciate any help or insights you or anyone else has, but I'm also hoping that anything we find is easy to swap out.

Thanks for any help!

swr2408018 is offline   Reply With Quote