Here is a servlet we use to generate PDF and HTML. For the PDF first it calls the transformer w/some parameters, then calls FOP. There's a lot going on, but you should be able to find the pieces you're looking for.
Using DOM trees to couple the transformation and the FO processor is a neat architecture, but could be inefficient for large intermediate FO structures. Using SAX events is better in this case.
J.Pietschmann