Not sure about the exact scope of the problem, but the attached test case fails. XPath in question: "id('a')/div".
Created attachment 12804 [details] test case
Created attachment 12897 [details] proposed fix Actually implement Path::doEvaluate().
Comment on attachment 12897 [details] proposed fix Looks fine, r=me.
Committed revision 19388.