you probably need a getRealNodeName somewhere in here, otherwise this will throw exceptions when getNode('?foo') returns a null value.

relatedly, maybe check for an NPE before calling getScope? We want to make sure there's a compile error downstream if the node doesn't exist.