I would have expected that such a feature would be easy to automate. However, the digital edition export is not built like most of the rest of InDesign, which has generally been created in C++, with careful attention to expose virtually all features to automation (hence the existence of this forum).
Instead, the functionality for digital edition export is realized via (compiled) scripts, i.e. those .jsxbin files in the Scripts > XHTML For Digital Editions folder where Adobe InDesign CS4 is installed.
So I guess that the functionality is not quite exposed to automation: you probably could call the .jsxbin files if you had documentation on how to call them. I don't see such documentation with InDesign, the scripting documentation, or the SDK.
If this is truly the case it represents a serious flaw in InDesign and a violation of the fundamental principle of exposure to automation that we've seen since version 1.0. This could of course be rectified quite easily by Adobe, simply by giving us enough info about how to call these binary scripts; let us hope they do this soon.
I hope I'm mistaken and someone can point to documentation on how to automate this, but I don't see it in the documentation, nor do I see answers to similar questions from a year ago.
I found a script here (post #4): http://forums.adobe.com/message/1926464#1926464 I think it can be easily remade to make it work with CS4 and loop through all documents of a book.
I can't do this right now since I will not have access to ID CS4 until Wednesday.
Yes we need to do something similar... however the XHTML export was provided as source and this is not. From your example:
var opts = new XHTMLExportOptions(); opts.styleHandling = XHTMLExportOptions.extStyleSheet; opts.styleSheet = 'template.css'; ...
We would have to guess at all the parameters like the XHTMLExportOptions structure - they are documented for XHTML export but not this variant of it.
You don't need to guess with CS4 for XHTML export: the source is available in the InDesign CS4 SDK available from http://www.adobe.com/devnet/indesign/sdk/eula_cs4.html
Source for the XHTML export scripts is in source > public > components > xhtmlexport
I asked Olav and he said that yes something like this approach would work and he will ask the team responsible to release the source and/or document how to use this script.
It would appear they did the right thing with XHTML export but dropped the ball on digital editions.
Note that we wouldn't want to do the iteration through files of a book; it would be preferable to simply be able to automate the equivalent of the book export option from the book panel.