XMLTransformer is a PHP library for transforming any kind of input XML into an output string. This output string does not have to be XML, but can also be, for instance, HTML or plain text.
The list of transformations XMLTransformer is able to perform includes:
- Removing tags, including or excluding the tag’s content
- Renaming attributes
- Removing attributes
- Adding attributes
- Changing attributes’ values
- Inserting content before and after a tag
- Inserting content at the beginning or end of tag content
- Transforming a tag including all of its content by passing it to a user-defined closure
- Performing any combination of the above
- Modifying the content of text nodes
What is it good for?
In my opinion, XMLTransformer performs very well if the input XML and the output to be produced are similarly structured. Moreover, if data from the input XML has to be processed by an existing PHP codebase, it is possibly cleaner and simpler to use XMLTransformer instead of XSL-T.
What is it not so good for?
When the input data has to be re-arranged, you are probably better off with XSL-T, as this is something that XMLTransformer does not provide. (Although to some extent it can be done with appropriate callback code.) Of course you are free to combine XSL-T with XMLTransformer to get the best of both worlds, if one is not enough.