The primary goal of this example is to illustrate how XSL Transforms can be applied to message fragments using Smooks. The source message in this example is XML, but it could easily be EDI, CSV, JSON etc depending on the configured Reader. The Fragment TransformerIn this example we build a very simple (silly) fragment transformer in XSLT. The transformation is totally trivial. The point of the example is purely to demonstrate how to hook in a fragment transformer into Smooks. So here's the XSLT we use in this tutorial: <!-- /example/BasicJavaTransformer.xsl --> It simply generates an "<xxx></xxx>" fragment for the currently matching "b" context element. The Smooks ConfigurationIn 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"): <?xml version="1.0"?> 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: <a> Smooks produces the following output: <a> Executing The Transformation// Instantiate Smooks with the config... Of course, you'd typically cache the Smooks instance. See the example/Main.java in the example source. |