boolean (@NotNull PsiElement element) { if (!(element instanceof XmlAttribute attr)) { return false; } if (!attr.isNamespaceDeclaration()) { return false; } final PsiFile file = attr.getContainingFile(); if (!(file instanceof XmlFile)) { return false; } // also catch namespace declarations in "normal" XML files that have XPath injected into some attributes // ContextProvider.hasXPathInjections() is an optimization that avoids to run the references search on totally XPath-free XML files if (!ContextProvider.hasXPathInjections((XmlFile)file) && !XsltSupport.isXsltFile(file)) { return false; } // This need to catch both prefix references from injected XPathFiles and prefixes from mode declarations/references: // <xsl:template match="*" mode="prefix:name" /> // BTW: Almost the same logic applies to other XML dialects (RELAX-NG). // Pull this class into the platform? final String prefix = attr.getLocalName(); final SchemaPrefix target = new SchemaPrefix(attr, TextRange.from("xmlns:".length(), prefix.length()), prefix); final Query<PsiReference> q = ReferencesSearch.search(target, new LocalSearchScope(attr.getParent())); return !q.forEach(psiReference -> { if (psiReference.getElement() == attr) { return true; } return false; }); }