Instead of using `doc` in the xpath expression I use `doc.defaultView.parent.document`. I don't understand what this is exactly doing, but hey, it seems to work!