3 Replies Latest reply on Feb 21, 2008 1:02 PM by standard

    Smooks: mixed transformation

    standard

      Hi,

      I have yet another question regarding Smooks in ESB, concerning the following scenario:

      I want to transform an incoming XML-message into another XML-message.
      I already have a rather complex XSLT that does the job, but wanted to try a more modular approach with Smooks,
      while keeping each part of the transformation simple and portable.

      Because of the structure of input and output I wanted to:
      - first apply a rather simple XSLT on the $document node of the input to transform it into the output structure
      -> producing a kinda intermediate format already in the right structure, but only with unchanged data from the input
      - then do all the complex enrichment stuff via Groovy with that intermediate format
      (already in the structure of the final output) on nodes of that intermediate format
      -> so producing the final output with data as needed here

      I looked at the transformation_ samples and the Smooks tutorials,
      but its seems the common use case is the other way around (first enrich, then transform via XSLT),
      which really isn't that good an option for me.

      When I execute this straight forward, it seems the enrichment doesn't work.
      I think this is because of the order in which the transformations beeing applied.
      I read that XSLT transformations aren't applied in the "visitBefore" phase per default.
      When it comes to the "visitAfter" phase, I think the XSLT-transformation is further down the list than the enrichment stuff (when I understand that demo right: http://milyn.codehaus.org/flash/DOMProcess.html).
      So the way I see it, Smooks tries to apply the enrichment transformations to the old input,
      which doesn't have the right format for it to work.
      I tried adding true to the XSLT transformation conf,
      while implementing the enrichment logic inside the visitAfter Method in Groovy, but it didn't work.

      I guess I could split the whole process into two complete different actions, (in fact I will try that right now) like in the transform_CSV2XML quickstart, but would prefer to keep it all together, if that is possible.


      My question is: is there, and whats is the best way to tell Smooks exactly how I want to have this done, or do I have to split the process into two actions?


      Thanks for the help
      Andreas

        • 1. Re: Smooks: mixed transformation
          tfennelly

          The Smooks DOM processing model first works out all of the nodes that have resources (transforms e.g. XSLTs) targeted at them... it then applies the resources to these nodes i.e. it only processes nodes that were in the original message. This is to avoid a situation where the processing of a DOM message spirals into an endless cycle of processing, adding, processing, adding etc

          To help get around this, Smooks DOM processing supports an "Assembly Phase", which is basically a pre-processing phase. So in your case, if you wanna execute the XSLT on the message before anything else, you can try adding the following param to the XSLT config:

          <param name="VisitPhase">ASSEMBLY</param>


          In general (IMO), XSLT sucks for what you're trying to do (actually... I think it sucks, full-stop). Based on what you described, I would be trying to perform a model driven approach for this type of transformation i.e. XML -> "Canonical Java Model" -> XML/EID etc, where your enrichment etc is being performed on the Canonical Java model and the Java -> XML transform is performed using a FreeMarker template (much much easier to grok than XSLT and easier to do stuff like looping, locale based formatting etc). Just a thought.


          • 2. Re: Smooks: mixed transformation
            standard

            Hi,

            thanks for the answer.
            I have to think about your idea, considering I already have the XSLT at hand...

            Do I understand you right, and you would make Java-Objects like in the transformXML2POJO quickstart (not having looked into that very closely until now)?
            It would make thinks allot easier for the following steps.
            I will most def look into that.

            As a side question, I remember reading about the Smooks "selector" format for fragments, but just can't find that link any more.
            Is it the same as e.g. in CSS, or are there any differences?
            Can I do a selection like "node1 node2[attr="value"]" or "node1 node2[attr]" or even fancier things :-)?

            Anyways, thank u very much for the help so far.

            Regards
            Andreas

            • 3. Re: Smooks: mixed transformation
              standard

              Hi,

              I now tried several ways to select a fragment with more complex conditions,
              but non of them worked.
              Is there no way to do finer selections with Smooks?

              Thanks for the answer.

              Regards
              Andreas