fix scope finding in xtemplate. Fixes #577