def pgnbr_add_next_attrib(pepxml):
    """
    Walk through page number "n" elements, and record page number sequence.  Add the next page number to
       the nextpgnum attribute of the n element.
    """

    # Walk through page number "n" elements, and record page number sequence
    n_nodes = pepxml.findall("**/n")
    lastPage = None
    count = 0
    # walk through the nodes backwards.
    for node in n_nodes[::-1]: # backwards
        pgNumber = node.text
        if lastPage is not None:
            node.set("nextpgnum", lastPage)
            count += 1
        # record the new pagenumber for the next node
        lastPage = pgNumber # .format()

    return count