How to add element content into its attribute value?








Trying to rewrite the output generated by a Sling rendering process from [A] to [B].

  • We can add an attribute (data-pt) at the startElement method of TrasformerFactory But struggle to get the value of its content (Test Drive) at the method startElement.
  • The value (Test Drive) available at methods characters  Or endElement of the transformer. Both the method does not have an option to add the attribute

Please let me know is it possible

  • to rewrite to [B] using sling rewriter?
  • If yes please get us the hint Or reference implementation example.
  • Otherwise any other recommendations? 

Thanks for your time.


<a href="">Test Drive</a>


<a href="" data-pt="Test Drive">Test Drive</a>

P.S: We are familiar with AEM materials & implementation.  Following articles really helped a lot & most of other internet blogs/kb are mostly based of it.  Please avoid responding with general google results.


Message was edited by: MC Stuff