<?xml version="1.0"?>

<ruleset name="Performance"
         xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">

    <description>
Rules that flag suboptimal code.
    </description>

    <rule name="AvoidAxisNavigation"
          language="xsl"
          since="5.0"
          message="Axis navigation has the largest impact when writing an XPath query."
          class="net.sourceforge.pmd.lang.rule.XPathRule"
          externalInfoUrl="${pmd.website.baseurl}/pmd_rules_xsl_performance.html#avoidaxisnavigation">
        <description>
Avoid using the 'following' or 'preceeding' axes whenever possible, as these can cut
through 100% of the document in the worst case.  Also, try to avoid using 'descendant'
or 'descendant-self' axes, as if you're at the top of the Document, it necessarily means
cutting through 100% of the document.
        </description>
        <priority>3</priority>
        <properties>
            <property name="xpath">
<!-- the use of node() allow to target any node with an select attribute
     but also workaround the ambiguity of having the xsl namespace in the
     node name.-->
                <value>
<![CDATA[
//node()[
  contains(@select,'preceeding::')
  or
  contains(@select,'following::')
  or
  contains(@select,'descendant::')
  or 
  contains(@select,'descendant-self::')
  or (
    ($checkSelfDescendantAbreviation = 'true' )
    and
    contains(@select,'//')
    )
]
]]>
                </value>
            </property>
            <property name="checkSelfDescendantAbreviation" type="Boolean" description="descendant::self abreviation, '//', will also trigger this rule." value="false"/>
        </properties>
        <example>
<![CDATA[
<xsl:variable name="var" select="//item/descendant::child"/>
]]>
        </example>
    </rule>

</ruleset>
