# Registering an attribute transformation with ppxlib

**URL:** <https://discuss.ocaml.org/t/registering-an-attribute-transformation-with-ppxlib/3131>\
**Category:** Learning\
**Tags:** ppxlib, ppx\
**Created:** [January 8, 2019, 12:57pm UTC](https://discuss.ocaml.org/t/registering-an-attribute-transformation-with-ppxlib/3131 "2019-01-08T12:57:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![steinuil](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/steinuil/32/993_2.png) [@steinuil](https://discuss.ocaml.org/u/steinuil)\
**Post date:** [January 8, 2019, 12:57pm UTC](https://discuss.ocaml.org/t/registering-an-attribute-transformation-with-ppxlib/3131/1 "2019-01-08T12:57:26Z")

</div>

I want to register a rewriter for ppxlib that matches expressions like this:

```auto
([@JSX] div ~children:[] ())

```

Generally it should match any expression with a `[@JSX]` attribute. The payload is always empty.

Is there an API to do this conveniently? The only one that’s documented is the `Extension` one.

---

<div class="post-metadata">

**Author:** ![steinuil](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/steinuil/32/993_2.png) [@steinuil](https://discuss.ocaml.org/u/steinuil)\
**Post date:** [January 9, 2019, 2:04pm UTC](https://discuss.ocaml.org/t/registering-an-attribute-transformation-with-ppxlib/3131/2 "2019-01-09T14:04:13Z")

</div>

Doesn’t look like there’s any “canonical” way to do this yet like there is for extensions, but the most convenient is to inherit from `Ast_traverse.map` and override the `#expression` method:

```ocaml
let map_exprs = object
  inherit Ast_traverse.map as super

  method! expression expr =
    let expr = super#expression expr in
    if contains_jsx expr.pexp_attributes then
      (* do the transform *)
    else
      expr
end

```

And then register the transformation with `~impl` and `~intf`:

```ocaml
let () =
  Ppxlib.Driver.register_transformation
    "ppx_jsx_tyxml"
    ~impl:map_exprs#structure
    ~intf:map_exprs#signature

```

---

<div class="post-metadata">

**Author:** ![joelreymont](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/joelreymont/32/5937_2.png) [@joelreymont](https://discuss.ocaml.org/u/joelreymont)\
**Post date:** [May 29, 2025, 7:31am UTC](https://discuss.ocaml.org/t/registering-an-attribute-transformation-with-ppxlib/3131/3 "2025-05-29T07:31:22Z")

</div>

Is this still the way to register an attribute transformation?
