Adding XML schema attributes to existing elements (e.g. XSLT)


I'm adding XML Schema files for vendor extensions to XSLT -- e.g. MarkLogic and Saxon. I can add the elements and attributes to the schema files; this part is working.

The issue I'm having is that the attributes are restricted to specific XSLT elements. For example, MarkLogic's xdmp:dialect element is restricted to xsl:stylesheet/xsl:template elements. With adding top-level xs:attribute definitions, those attributes are auto-completed and validated on all elements. I could perform additional validation in an inspection, but the auto-complete behaviour would still be present.

I have tried extending/modifying the XSLT elements in the vendor extension schema file, but that version is not located.

I could try modifying the xslt schema files to add the vendor extension attributes there, but I'm not sure if this will work with the xslt 2 schema, as that is registered by the IntelliJ platform (specifically, if registering an xslt 2 schema file in my plugin will override the IntelliJ schema file). The vendor extension attributes are also in different namespaces, so I don't know if IntelliJ only uses the targetNamespace to search for element definitions. Otherwise, there is a cyclic reference between the xslt and vendor schema files -- is this handled by IntelliJ?

Is there another way to define the extension attributes in the XML schema file such that they are limited to specific XSLT elements, or are any of the above the recommended way to achieve this functionality?


Hi, you can try to register a com.intellij.psi.impl.source.xml.XmlElementDescriptorProvider and return your custom com.intellij.xml.XmlElementDescriptor for specific tags. The XmlElementDescriptor should wrap original one obtained from xsd-based XmlNSDescriptor, and filter returned XmlAttributeDescriptors. 

For further details, please refer to com.intellij.psi.impl.source.xml.XmlTagDelegate#computeElementDescriptor method.


Great, thanks. I'll take a look at those APIs.


Please sign in to leave a comment.