code: def merge_into_nodeset(target, source):
      
      if len(target) == 0:
          target.extend(source)
          return
  
      source = [n for n in source if n not in target]
      if len(source) == 0:
          return
  
      # If the last node in the target set comes before the first node in the
      # source set, then we can just concatenate the sets.  Otherwise, we
      # will need to sort.  (We could also check to see if the last node in
      # the source set comes before the first node in the target set, but this
      # situation is very unlikely in practice.)
      if document_order(target[-1]) < document_order(source[0]):
          target.extend(source)
      else:
          target.extend(source)
          target.sort(key=document_order)
docs: Place all the nodes from the source node-set into the target
      node-set, preserving document order.  Both node-sets must be in
      document order to begin with.