# Customize

### Custom pseudo-class

Custom pseudo-classes extends the `PseudoClass` and implements `match(Node node)`. This method should return `true` if a node is matched. You may also override the method `getPseudoClassName()` if you don't want to generate a pseudo-class name from the class name. For example:

```java
public class MyPseudoClass extends PseudoClass {
    @Override
    public boolean match(Node node) {
      return node.hasAttribute("jodd-attr");
    }

    @Override
    public String getPseudoClassName() {
      return "jodd";
    }
}
```

Then register your pseudo-class with:

```java
    PseudoClassSelector.registerPseudoClass(MyPseudoClass.class);
```

From that moment you will be able to find all nodes with the attribute `jodd-attr` using the `:jodd` pseudo-class.

When a pseudo-class needs to perform an additional match in the range of matched nodes (e.g. first, last etc), then override `matchInRange()` method, too.

### Custom pseudo-function

Similar to pseudo-classes, custom pseudo-function implements the `PseudoFunction` class. Additionally, you need to also implement a method that parses input expression. This expression is later passed to the matching method.

Let's make a function that matches all nodes with certain name length:

```java
public class MyPseudoFunction extends PseudoFunction {
    @Override
    public Object parseExpression(String expression) {
        return Integer.valueOf(expression);
    }

    @Override
    public boolean match(Node node, Object expression) {
        Integer size = (Integer) expression;
        return node.getNodeName().length() == size.intValue();
    }

    @Override
    public String getPseudoFunctionName() {
        return "len-fn";
    }
}
```

Register it with:

```java
PseudoFunctionSelector.registerPseudoFunction(MyPseudoFunction.class);
```

Start using it! E.g. `:len-fn(3)` to match all nodes with short names:)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lagarto.jodd.org/csselly/customize.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
