Fix querying detached nodes and document fragments by id

This PR should fix [issue #17699](https://bugs.dojotoolkit.org/ticket/17699).