docs: def process_reference_line(working_line,
                             journals_matches,
                             pprint_repnum_len,
                             pprint_repnum_matchtext,
                             publishers_matches,
                             removed_spaces,
                             standardised_titles,
                             kbs):
      """After the phase of identifying and tagging citation instances
         in a reference line, this function is called to go through the
         line and the collected information about the recognised citations,
         and to transform the line into a string of MARC XML in which the
         recognised citations are grouped under various datafields and
         subfields, depending upon their type.
         @param line_marker: (string) - this is the marker for this
          reference line (e.g. [1]).
         @param working_line: (string) - this is the line before the
          punctuation was stripped. At this stage, it has not been
          capitalised, and neither TITLES nor REPORT NUMBERS have been
          stripped from it. However, any recognised numeration and/or URLs
          have been tagged with <cds.YYYY> tags.
          The working_line could, for example, look something like this:
           [1] CDS <cds.URL description="http //invenio-software.org/">
           http //invenio-software.org/</cds.URL>.
         @param found_title_len: (dictionary) - the lengths of the title
          citations that have been recognised in the line. Keyed by the index
          within the line of each match.
         @param found_title_matchtext: (dictionary) - The text that was found
          for each matched title citation in the line. Keyed by the index within
          the line of each match.
         @param pprint_repnum_len: (dictionary) - the lengths of the matched
          institutional preprint report number citations found within the line.
          Keyed by the index within the line of each match.
         @param pprint_repnum_matchtext: (dictionary) - The matched text for each
          matched institutional report number. Keyed by the index within the line
          of each match.
         @param identified_dois (list) - The list of dois inside the citation
         @identified_urls: (list) - contains 2-cell tuples, each of which
          represents an idenitfied URL and its description string.
          The list takes the order in which the URLs were identified in the line
          (i.e. first-found, second-found, etc).
         @param removed_spaces: (dictionary) - The number of spaces removed from
          the various positions in the line. Keyed by the index of the position
          within the line at which the spaces were removed.
         @param standardised_titles: (dictionary) - The standardised journal
          titles, keyed by the non-standard version of those titles.
         @return: (tuple) of 5 components:
                    ( string  -> a MARC XML-ized reference line.
                      integer -> number of fields of miscellaneous text marked-up
                                 for the line.
                      integer -> number of title citations marked-up for the line.
                      integer -> number of institutional report-number citations
                                 marked-up for the line.
                      integer -> number of URL citations marked-up for the record.
                      integer -> number of DOI's found for the record
                      integer -> number of author groups found
                    )
  
      """
      if len(journals_matches) + len(pprint_repnum_len) + len(publishers_matches) == 0:
          # no TITLE or REPORT-NUMBER citations were found within this line,
          # use the raw line: (This 'raw' line could still be tagged with
          # recognised URLs or numeration.)
          tagged_line = working_line
      else:
          # TITLE and/or REPORT-NUMBER citations were found in this line,
          # build a new version of the working-line in which the standard
          # versions of the REPORT-NUMBERs and TITLEs are tagged:
          startpos = 0          # First cell of the reference line...
          previous_match = {}   # previously matched TITLE within line (used
          # for replacement of IBIDs.
          replacement_types = {}
          journals_keys = journals_matches.keys()
          journals_keys.sort()
          reports_keys = pprint_repnum_matchtext.keys()
          reports_keys.sort()
          publishers_keys = publishers_matches.keys()
          publishers_keys.sort()
          spaces_keys = removed_spaces.keys()
          spaces_keys.sort()
          replacement_types = get_replacement_types(journals_keys,
                                                    reports_keys,
                                                    publishers_keys)
          replacement_locations = replacement_types.keys()
          replacement_locations.sort()
  
          tagged_line = u""  # This is to be the new 'working-line'. It will
          # contain the tagged TITLEs and REPORT-NUMBERs,
          # as well as any previously tagged URLs and
          # numeration components.
          # begin:
          for replacement_index in replacement_locations:
              # first, factor in any stripped spaces before this 'replacement'
              true_replacement_index, extras = \
                  account_for_stripped_whitespace(spaces_keys,
                                                  removed_spaces,
                                                  replacement_types,
                                                  pprint_repnum_len,
                                                  journals_matches,
                                                  replacement_index)
  
              if replacement_types[replacement_index] == u"journal":
                  # Add a tagged periodical TITLE into the line:
                  rebuilt_chunk, startpos, previous_match = \
                      add_tagged_journal(
                          reading_line=working_line,
                          journal_info=journals_matches[replacement_index],
                          previous_match=previous_match,
                          startpos=startpos,
                          true_replacement_index=true_replacement_index,
                          extras=extras,
                          standardised_titles=standardised_titles)
                  tagged_line += rebuilt_chunk
  
              elif replacement_types[replacement_index] == u"reportnumber":
                  # Add a tagged institutional preprint REPORT-NUMBER
                  # into the line:
                  rebuilt_chunk, startpos = \
                      add_tagged_report_number(
                          reading_line=working_line,
                          len_reportnum=pprint_repnum_len[replacement_index],
                          reportnum=pprint_repnum_matchtext[replacement_index],
                          startpos=startpos,
                          true_replacement_index=true_replacement_index,
                          extras=extras
                      )
                  tagged_line += rebuilt_chunk
  
              elif replacement_types[replacement_index] == u"publisher":
                  rebuilt_chunk, startpos = \
                      add_tagged_publisher(
                          reading_line=working_line,
                          matched_publisher=publishers_matches[
                              replacement_index],
                          startpos=startpos,
                          true_replacement_index=true_replacement_index,
                          extras=extras,
                          kb_publishers=kbs['publishers']
                      )
                  tagged_line += rebuilt_chunk
  
          # add the remainder of the original working-line into the rebuilt line:
          tagged_line += working_line[startpos:]
  
          # we have all the numeration
          # we can make sure there's no space between the volume
          # letter and the volume number
          # e.g. B 20 -> B20
          tagged_line = wash_volume_tag(tagged_line)
  
      # Try to find any authors in the line
      tagged_line = identify_and_tag_authors(tagged_line, kbs['authors'])
      # Try to find any collaboration in the line
      tagged_line = identify_and_tag_collaborations(tagged_line,
                                                    kbs['collaborations'])
  
      return tagged_line.replace('\n', '')