PsiElement (XPathExpression reference) { final XmlTag template = getTemplateTag(reference, true); final XmlTag tag = PsiTreeUtil.getContextOfType(reference, XmlTag.class, true); assert tag != null; return template != null ? template.getNavigationElement() : tag.getParentTag(); }