JetBrains Rider 2018.2 Help

Code Inspections in XPath

Inspection

Description

Default Severity

Check Node Test

This inspection checks whether any element/attribute names that are used in XPath-expressions are actually part of an associated XML file or are defined in a referenced schema. This helps to avoid problems caused by typos in XPath-expressions that would otherwise occur when running the script and may even then not be recognized immediately.

Example:

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

If the prefix "h" is bound to the XHTML namespace, the inspection will flag this part of the match-expression as an unknown element name because the correct name of the element is "textarea".

Warning

Implicit Type Conversion

This inspection checks for any implicit conversions between the predefined XPath-types STRING, NUMBER, BOOLEAN and NODESET. While this is usually not a problem as the conversions are well-defined by the standard, this inspection can help to write XSLT scripts that are more expressive about types and can even help to avoid 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). The plugin will then offer to make the type-conversion more explicit.

There are several options to adjust the inspection to personal preferences by offering the possibility to individually enable it for implicit conversions between certain types.

The plugin can also be told to always flag explicit conversions that do not result in the actually expected type, such as <xsl:if test="number(foo)" /> and provides a special option to ignore the conversion from NODESET to BOOLEAN by using the string() function as a shortcut for writing string-length() > 0.

Warning

Redundant Type Conversion

This inspection checks whether any type-conversion with the functions string(), number() or boolean() is redundant, i.e. whether the type of argument is the same as the functions return type or if the expected type of the expression is of type "any". While such an explicit conversion may sometimes be intentional to emphasize the type, this can usually be safely removed.

Warning

Use of index 0 in XPath predicates

This inspection checks for any accidental use of zero in a predicate index or in a comparision with the function position(). Such is almost always a bug because in XPath, the index starts at one, not at zero.

Example:

//someelement[position() = 0] or //something[0]

Warning

Hardwired Namespace Prefix

This inspection checks for comparisons of the name()-function against strings that contain a ":" - which usually indicates a hardwired namespace-prefix in the comparison. Such code will break when run against XML that uses a different prefix for the same namespace.

Example:

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

Warning

Last modified: 21 December 2018