PhpStorm 2023.3 Help

Code Inspections in XPath

This topic lists all PhpStorm 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.

Inspection

Description

Default Severity

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.

Example:

<xsl:if test="name() = 'xlink:href'">...<xsl:if>

Warning Warning

Implicit type conversion

Reports implicit conversions between the predefined XPath-types STRING, NUMBER, BOOLEAN, and NODESET. Helps to write XSLT scripts that are more expressive about types and prevents subtle bugs:

Example:

<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 NODESET to BOOLEAN by using the string() function as a shortcut for writing string-length() > 0.

Warning Warning

Redundant type conversion

Reports unnecessary type conversions. Type conversions are unnecessary when the argument type of a string(), number(), or 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.

Warning Warning

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.

Example:

<xsl:template match="h:txtarea" />

If the 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".

Warning Warning

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 0.

Example:

//someelement[position() = 0]

or //something[0]

Warning Warning

Last modified: 25 March 2024