Simplified XPath value serialization and ensured that document is only converted to a document fragment if it has 2 or more children. If it has only a single child, then that child is the node to put to xpathval and not the document node.