9 Replies Latest reply on Sep 26, 2007 7:16 AM by tobysaville

    Smooks Transform outputs same XML

    tobysaville

      Hello,

      when i attempt to transform XML via XSLT using Smooks, the result is the same as the input XML.

      I have transformed the XML using Xalan, and it transforms correctly, however, when i use Smooks, no transformation occurs.

      I have tried using the SmooksTransformer Action, as well as a separate unit test that loads the smooks-res.xml config file, but neither work.

      Unit test code

      String xml = new XStream().toXML(myObject);
      Smooks smooks = new Smooks("smooks-res.xml");
      TemplatingUtils.registerCDUCreators(smooks);
      StandaloneExecutionContext executionContext = smooks.createExecutionContext();
      
      String result = SmooksUtil.filterAndSerialize(
       executionContext,
       new ByteArrayInputStream(xml.getBytes()),
       smooks);
      


      smooks-res.xml file:
      <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
      
       <resource-config selector="$document">
       <resource>/dslCheckRequestTemplate.xsl</resource>
       <param name="is-xslt-templatelet">true</param>
       </resource-config>
      
      </smooks-resource-list>
      


      i can provide logs etc if that would help.

      cheers,
      toby

        • 1. Re: Smooks Transform outputs same XML
          tfennelly

          I'd guess your issue is re the paramater is-xslt-templatelet=true. Looks as though you're not using a templatelet, but instead using a full stylesheet.

          • 2. Re: Smooks Transform outputs same XML
            tobysaville

            thanks Tom,

            it doesnt seem to change anything - if its true, false, or removed completely.

            cheers,
            tobes

            • 3. Re: Smooks Transform outputs same XML
              tfennelly

              OK Toby, nothing further to suggest - I'd need everything you've got here in front of me. You could try turning on debug logging on the Smooks stuff - will tell you (in detail) what is and is not getting applied and why. You could also try taking one of the working examples from http://milyn.codehaus.org/Tutorials and modifying it.

              • 4. Re: Smooks Transform outputs same XML
                burrsutter

                Hey Toby,

                I've not been following this thread completely but is it possible that Smooks did the job but then stuck the transformed message into some odd place into the Message object. You might use the SystemPrintln action printfull option to see if you can find the results hidden away some place. The SystemPrintln action is used in helloworld_file_action and is documented in the MessageActionGuide.

                <action name="dump" class="org.jboss.soa.esb.actions.SystemPrintln">
                 <property name="printfull" value="true"/>
                </action>
                


                • 5. Re: Smooks Transform outputs same XML
                  tobysaville

                  Hi Tom, Burr,

                  thanks again for your help with this.

                  As it turns out, smooks didnt like the "/" in my xsl:template tag. The following didnt work:

                  <xsl:template match="/Order">
                  <!-- OR -->
                  <xsl:template match="/">
                  

                  However the following did
                  <xsl:template match="Order">
                  


                  So it was just my lack of understanding of Smooks. I assume this means that $document in smooks-res.xml refers to the root XPath ("/") of the XML being parsed. Is that correct?

                  Thanks again!
                  - tobes



                  • 6. Re: Smooks Transform outputs same XML
                    tfennelly

                     

                    "tobysaville" wrote:
                    I assume this means that $document in smooks-res.xml refers to the root XPath ("/") of the XML being parsed. Is that correct?


                    Basically, yes. selector="$document" targets the resource at the "document fragment", which is basically the root node in the document. Check out the Smooks FAQs.

                    • 7. Re: Smooks Transform outputs same XML
                      tobysaville

                      nice, thanks again Tom.

                      i have another question, but im not sure if i should start a new thread, or even post this to a smooks specific forum, but seeing as your a Smooks developer too, Tom, i thought i would start here.

                      Can you tell me why the variable below called $install would have a value of 2 when processed with Xalan, and a value of 0 when using Smooks (xalan indirectly, i believe?)

                      <xsl:param name="installs" select="//Service/customer"/>
                      
                      <xsl:param name="install" select="count($installs)"/>
                      


                      However, if i do the following, the value of $install is 2 using Xalan or Smooks:

                      <xsl:param name="services" select="//Service"/>
                      
                      <xsl:param name="install" select="count($services/customer)"/>
                      


                      i have also tried using <xsl:variable/> instead of <xsl:param/>

                      thanks again,
                      - tobes

                      • 8. Re: Smooks Transform outputs same XML
                        tfennelly

                         

                        "tobysaville" wrote:
                        i have another question, but im not sure if i should start a new thread, or even post this to a smooks specific forum


                        Sure. These are Smooks specific questions, so perhaps it's better to address them on the Smooks Users mailing list.

                        "tobysaville" wrote:
                        Can you tell me why the variable below called $install would have a value of 2 when processed with Xalan, and a value of 0 when using Smooks (xalan indirectly, i believe?)

                        <xsl:param name="installs" select="//Service/customer"/>
                        
                        <xsl:param name="install" select="count($installs)"/>
                        


                        However, if i do the following, the value of $install is 2 using Xalan or Smooks:

                        <xsl:param name="services" select="//Service"/>
                        
                        <xsl:param name="install" select="count($services/customer)"/>
                        


                        i have also tried using <xsl:variable/> instead of <xsl:param/>

                        thanks again,
                        - tobes


                        This is most likely down to the Smooks processing model again i.e. the fact that it's fragment based. The difference is that Smooks applies XSL transforms by targeting them at DOM Element nodes (even if that node is the root node ala "$document") Vs the whole Document (DOM Document node). It should obviously try to be more consistent with applying XSL standalone, so we should log this as a bug. It could be fixed by making a special case of XSL targeted at the "$document" node.

                        • 9. Re: Smooks Transform outputs same XML
                          tobysaville

                          Hi Tom,

                          thanks again for your help, ill take these issues to the smooks mailing list.

                          see you there :)

                          - tobes