Skip to main content

Fun with the NetBeans DocBook modules, XSL compiler hell

Posted by timboudreau on October 16, 2006 at 12:34 AM PDT

I've got a bunch of writing projects going lately. There is a NetBeans DocBook module, if you like writing articles and books in XML (doesn't everyone?). I've had some fun enhancing it over the weekend...

Jesse Glick created the NetBeans DocBook module (cvs -d:pserver:anoncvs@cvs.netbeans.org:/cvs co contrib) a couple of years ago. It provides support for writing articles, presentations, and now books, using DocBook XML—it's a handy way to write an article using logical markup (i.e. chapters, sections, etc.), and then transform it into HTML, PDF or navigational instructions for skywriting (well, that transform has yet to be written). Perhaps it's a way of writing only a programmer could love—it's the antithesis of WYSIWYG—but it's pretty darned useful if you're going to hand something off to a publisher and want a publisher-friendly format, and you also want to put the work in CVS and collaborate on it, but still have support for abstracts and footnotes and endnotes and that sort of stuff. And since it's NetBeans XML editor you get code completion for the DTD and other Good Stuff™.

I've added a DocBook project module to the mix that lets you treat an article or book as a NetBeans project and "compile" it to HTML. It's all pre-alpha quality right now (hence no downloads yet), but it's coming along.

The killer (however undiscoverable) feature is the ability to paste images into the XML. Since a lot of what I write is about NetBeans, I thought...why not just let someone paste in an image. So I tweaked the TransferHandler for the editor, so that if you paste and an image is on the clipboard, it will pop up a nice little dialog that asks you for a name; then it pops up a window that lets you crop the image; finally it uses ImageIO to save it adjacent to the file you're editing and inserts a reference to it as a

in the XML. Seems pretty handy so far. I was thinking this could be added to the HTML editor in NetBeans if people think it would be useful.

The current fly in all of this lovely ointment is finding an XSL compiler that doesn't choke on the DocBook to FO stylesheets - it would be very nice to be able to compile down to PDF format using Apache FOP. I've tried the XSL support JDK 6, Saxon 6.5, Saxon 8, and miscellaneous other things. Has anybody out there solved this problem? I confess I don't spend most of my coding time processing XML (last of a dying breed :-)), so perhaps I'm missing something obvious.