The primary goals of this example are to introduce you to the following:
- A very basic Fragment Transformer written in XSLT.
- The Smooks configuration file.
- Executing the Smooks Transformation.
To Build: "mvn clean install"
To Run: "mvn exec:java"
The Fragment Transformer
In this example we build a very simple (silly) fragment transformer in XSLT. The applied transform is exactly the same as that carried out in the "java-basic" tutorial. Sure, it's totally trivial. The point of this tutorial is purely to demonstrate how to hook in a fragment transformer into Smooks. More realistic usecases can be seen in some of the other tutorials.
So here's the XSLT we use in this tutorial:
It simply generates an "<xxx></xxx>" fragment for the currently matching "b" context element.
The Smooks Configuration
In order to apply this transformer to a message fragment, a Smooks Configuration needs to be created. This configuration will target the transformer at a particular message fragment.
Here's the configuration ("smooks-config.xml"):
As with the java-basic tutorial, the resource-config tells Smooks to apply the "/example/BasicJavaTransformer.xsl" resource on all <b> elements that are enclosed by a parent <c> element.
So, taking the sample message supplied with this example:
Smooks produces the following output(same as with the java-basic tutorial):
Executing The Transformation
Again, it's exactly the same as with the java-basic tutorial:
Of course, you'd typically cache the Smooks instance.
See the example/Main.java in the example source.