Highlighting errors in XSLT
The XSLT support can detect a range of errors in XSLT constructs, such as misspelled template names, missing template parameters, bad match-patterns, references to undeclared variables, wrong or useless embedded XPath expressions, and so on and also offers Quick Fixes to automatically fix some of those errors.
Syntax highlighting
Where allowed, XPath function-calls, Axis names, Numbers, Strings, and so on are highlighted according to the currently active color scheme. If a different coloring is desired, those colors can be configured in the tab on the Color Scheme page of the Settings/Preferences.
XPath syntax checks
Just like the interactive XPath Expression Evaluation, the XSLT support catches any syntax error in XPath expressions used inside a Style Sheet.
![XPath Syntax check XPath Syntax check](https://resources.jetbrains.com/help/img/idea/2022.1/syntax.png)
XPath type checking
In XPath, almost all types are assignable to each other with certain well-defined conversion semantics. However, the conversion to NODESET isn't defined for any type and there's also no (portable) conversion function available. Such type-conversions are highlighted as an error.
![Type Check Type Check](https://resources.jetbrains.com/help/img/idea/2022.1/conversion-to-nodeset.png)
Pattern validation
A special form of XPath expression are patterns in XSLT. They are e.g. used as the value of the match-attribute in xsl:template
elements. Only a certain subset of XPath expressions is allowed here, which the XSLT support checks for.
![Pattern Check Pattern Check](https://resources.jetbrains.com/help/img/idea/2022.1/bad-pattern.png)
Unresolved references
References to variables that have not been declared or are not accessible from the current scope are detected and highlighted as an error. There are Quick Fixes available to create a variable or parameter declaration for such unresolved variables references.
![Unresolved Variable Unresolved Variable](https://resources.jetbrains.com/help/img/idea/2022.1/unresolved-var.png)
Quick-fixes:
![QuickFixes for Unresolved Variables QuickFixes for Unresolved Variables](https://resources.jetbrains.com/help/img/idea/2022.1/unresolved-var-quickfix.png)
Duplicate declarations
In XSLT there must not be more than one variable or parameter declared on the same scope level. It's also not allowed that there is more than one template with the same name. The plugin will identify such duplicate declarations and highlight them in the editor.
Other checks
Shadowed variables
Even though it is possible to have identically named variables or parameters in different nesting levels, this can be confusing and is likely to cause programming mistakes. The plugin can identify shadowed declarations and offers Quick-Fixes to either rename the local or the outer variable.
Missing template arguments
Another check that the XSLT support performs is whether all required parameters are specified with a xsl:call-template
. A parameter is considered required if there is no default value, i.e. if there's no select attribute and the paremeter's declaring element has an empty body.
![Missing Template-Invocation Argument Missing Template-Invocation Argument](https://resources.jetbrains.com/help/img/idea/2022.1/missing-argument.png)
Quick-Fixes:
![Missing Argument QuickFixes Missing Argument QuickFixes](https://resources.jetbrains.com/help/img/idea/2022.1/missing-argument-quickfix.png)
Superfluous template arguments
There's also a supplemental check that flags arguments that are not declared as template parameters. There are Quick Fixes available to either remove the argument from the template-call or to add a corresponding parameter to the called template.
![Superfluous Template-Invocation Argument Superfluous Template-Invocation Argument](https://resources.jetbrains.com/help/img/idea/2022.1/superfluous-param.png)
Quick-fixes:
![Superfluous Argument QuickFixes Superfluous Argument QuickFixes](https://resources.jetbrains.com/help/img/idea/2022.1/superfluous-param-quickfix.png)
Function call arguments
The XSLT support does, just like the interactive XPath Expression Evaluation, check whether the number and types of function arguments match their declaration for built-in functions of XPath and XSLT.
![Missing XPath Function Argument Missing XPath Function Argument](https://resources.jetbrains.com/help/img/idea/2022.1/missing-function-argument.png)
XPath inspections
All XPath inspections are supported for editing XSLT documents. Those inspections can also be suppressed in a way that is similar to the standard suppression-mechanism PhpStorm uses for Java code by using noinspection XML comments. The suppression is possible on different levels, either on instruction level, template-level (if applicable) or Style Sheet level.