title: How to write a custom java rule for XSLT files
body: <p>I'm writing a custom rule for xslt files. The rule is to check for the presence of any tags within comments in xslt files. I did this same check for xml files as shown below. What (rule) class to extend and what method to override for making this work for xslt files?</p>
  
  <pre><code>import java.util.regex.Pattern;
  import net.sourceforge.pmd.RuleContext;
  import net.sourceforge.pmd.lang.xml.ast.XmlNode;
  import net.sourceforge.pmd.lang.xml.rule.AbstractDomXmlRule;
  import org.w3c.dom.Comment;
  
  public class CommentedCodeRule extends AbstractDomXmlRule {
      private static final Pattern TAG = Pattern.compile("&lt;\\w+&gt;");
  
      @Override
      protected void visit(XmlNode node, Comment comment, RuleContext ctx) {
          if (hasTag(comment)) {
              addViolation(ctx, node);
          }
          super.visit(node, comment, ctx);
      }
  
      private static boolean hasTag(Comment comment) {
          return TAG.matcher(comment.getData()).find();
      }
  }
  </code></pre>
  
  <p>UPDATE - Adding the ruleset xml used</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;ruleset name="quickstart"
           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 https://pmd.sourceforge.io/ruleset_2_0_0.xsd"&gt;
  
      &lt;description&gt;"Commented-out code" check.&lt;/description&gt;
  
      &lt;rule name="CommentedCodeXml"
            language="xml"
            since="3.0"
            message="Found commented-out code."
            class="CommentedCodeRule"
            externalInfoUrl=""&gt;
          &lt;description&gt;
              Production code should not contain any commented-out code. It suggests an incomplete implementation, 
              and consequently, decreases confidence in the code.
          &lt;/description&gt;
          &lt;priority&gt;3&lt;/priority&gt;
      &lt;/rule&gt;
      &lt;rule name="CommentedCodeXsl"
            language="xsl"
            since="3.0"
            message="Found commented-out code."
            class="CommentedCodeRule"
            externalInfoUrl=""&gt;
          &lt;description&gt;
              Production code should not contain any commented-out code. It suggests an incomplete implementation, 
              and consequently, decreases confidence in the code.
          &lt;/description&gt;
          &lt;priority&gt;3&lt;/priority&gt;
      &lt;/rule&gt;
  &lt;/ruleset&gt;
  </code></pre>