Code Inspections in XPath
This topic lists all DataGrip code inspections available in XPath.
You can toggle specific inspections or change their severity level on the Editor | Inspections page of the IDE settings Ctrl+Alt+S.
Hardcoded namespace prefix
Reports comparisons of the
name() function with a string that contains a colon (
:). Such usages usually indicate a hardcoded namespace prefix in the comparison. As a result, the code will break when run against XML that uses another prefix for the same namespace.
<xsl:if test="name() = 'xlink:href'">...<xsl:if>
Implicit type conversion
Reports implicit conversions between the predefined XPath-types
NODESET. Helps to write XSLT scripts that are more expressive about types and prevents subtle bugs:
<xsl:if test="foo" />
is not the same as
<xsl:if test="string(foo)" />
The first test checks whether the element "foo" exists (
count(foo) > 0); the latter one however is only true if the element actually contains any text (
string-length(foo) > 0). Suggests making the type conversion more explicit.
Use the following options to configure the inspection:
Enable or disable implicit conversions between certain types
Always report explicit conversions that do not result in the actually expected type, for example,
<xsl:if test="number(foo)" />
Ignore conversion from
BOOLEAN by using the
string() function as a shortcut for writing
string-length() > 0.
Redundant type conversion
Reports unnecessary type conversions. Type conversions are unnecessary when the argument type of a
boolean() function is already the same as the function's return type or if the expected expression type is
any. Suggests removing the unnecessary conversion.
Unknown element or attribute name
Reports names of elements or attributes that are used in an XPath-expression but are missing in the associated XML files and are not defined in the referenced schemas. Such names are often the result of typos and would otherwise probably only be discovered at runtime.
<xsl:template match="h:txtarea" />
h is bound to the XHTML namespace, the inspection will report this part of the
match expression as an unknown element name because the correct name of the element is "textarea".
XPath predicate with index 0
Reports usages of
0 in a predicate index or in a comparison with the function
position(). Such usage is almost always a bug because in XPath, the index starts at
1, not at
//someelement[position() = 0]
Last modified: 21 March 2023