Fix issue #171 by checking for a null input document
Copy the attributes too!