Next / Previous / Contents / Shipman's homepage

6.9. extractTitle: Find the document title

# - - -   e x t r a c t T i t l e

def extractTitle(inDoc):
    '''Find the title text of the DocBook document.

      [ inDoc is an et.ElementTree ->
          return the title text from inDoc rendered as an
          FO inline, with selected subelements rendered as FO
          and the rest ignored ]

XPath returns a list of the title elements, which there had better be exactly one.

    #-- 1
    # [ if inDoc has exactly one document title elements ->
    #     titleNode  :=  that element
    #   else ->
    #     sys.stderr  +:=  error message
    #     stop execution ]
    titleNodeList = inDoc.xpath('/article/articleinfo/title')
    if len(titleNodeList) < 1:
        fatal("Can't find the title element!")
        titleNode = titleNodeList[0]

In general, a title may contain markup; Section 6.10, “renderTitle(): Remove tags from a title element. Test case: ABCD” translates the title text, and selected markup, into FO.

    #-- 2
    # [ return titleNode as an FO inline, with selected markup
    #   rendered as FO and the rest ignored ]
    return renderTitle(titleNode)