Next / Previous / Contents / Shipman's homepage

6.13. buildFlowTree: Set up an XSL-FO output document

# - - -   b u i l d F l o w T r e e

def buildFlowTree(docTitle, timestamp):
    '''Set up an XSL-FO document for the output.

      [ (docTitle is the document's title as an inline) and
        (timestamp is a timestamp string) ->
          return (an h.FlowTree instance with the desired output
          page structure, the flow element in that instance) ]

First we call the constructor for the FlowTree class to build an XSL-FO skeleton.

    #-- 1
    # [ tree  :=  a new, empty FlowTree instance ]
    tree = h.FlowTree()

Section 6.14, “addMasters(): Set up the page masters” builds the children of the layout-master-set.

    #-- 2
    # [ tree.masters  +:=  simple-page-master elements for
    #       odd and even pages and a page-sequence-master
    #       that alternates them ]

Section 6.15, “buildPageSequence(): Set up the page sequence and headers” adds the single page-sequence child to the root element, and returns that element. It also adds static-content children to the page-sequence for the odd-side and even-side headers.

    #-- 3
    # [ tree.root  +:=  a new page-sequence element with
    #       static-content children defining the header content
    #       of the ODD_BEFORE and EVEN_BEFORE regions using
    #       docTitle and timestamp
    #   pages  :=  that page-sequence element ]
    pages = buildPageSequence(tree.root, docTitle, timestamp)

All that remains is to add the page-sequence's last child, the flow element, and return the FlowTree and the flow element.

    #-- 4
    # [ pages  +:=  a new 'flow' element
    #   flow  :=  that element ]
    flow = subElement(pages, h.flow())

    #-- 5
    return (tree, flow)