6 Replies Latest reply on Jul 6, 2009 8:04 AM by ravikiran_tv

    Problem in XML to CSV transformation

      I am exploring jboss-soa-p.4.2.0. I am facing a problem with XML to CSV transformation.
      Smooks does not give any direct way of XML to CSV transformation.So I have tried this transformation using XSLT but it is not working as desired.

      The trouble is it is not working when I am running this with jboss-soa-p.4.2.0 which uses Smooks 0.9. This works correctly with Smooks 1.0 used in later versions of Jboss ESB .

      In the result with Smooks 0.9, i am getting the desired csv within the root element "AssignedTaskDetails".

      My input xml is :

      <xml version="1.0"?>
      <AssignedTaskDetails>
       <task>
       <TaskId>641f71c1</TaskId>
       <TaskDescription>Javatesting</TaskDescription>
       <TaskCompletionTime> EOD</TaskCompletionTime>
       <TaskresponseDetails>ok</TaskresponseDetails>
       <isCancelled>false</isCancelled>
       <isCompleted>false</isCompleted>
       </task>
       <task>
       <TaskId>845dfdf0</TaskId>
       <TaskDescription>Javacoding</TaskDescription>
       <TaskCompletionTime>Urgent</TaskCompletionTime>
       <TaskresponseDetails> will do</TaskresponseDetails>
       <isCancelled>false</isCancelled>
       <isCompleted>false</isCompleted>
       </task>
      </AssignedTaskDetails>
      

      The result I obtain is:
      <AssignedTaskDetails>
       641f71c1,Javatesting,EoD,ok,false,false
      
       845dfdf0,Javacoding,Urgent,yps,false,false
      
       </AssignedTaskDetails>


      The smooks config is:
      <?xml version='1.0' encoding='UTF-8'?>
      <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
       <resource-config selector="task">
       <resource>BasicXslTransform.xsl</resource>
       </resource-config>
      </smooks-resource-list>


      My BasicXslTransform is:
      <?xml version="1.0" encoding="UTF-8"?>
      <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="text"/>
      <xsl:template match="AssignedTaskDetails">
       <xsl:apply-templates select="task"/>
      </xsl:template>
      <xsl:template match="task">
       <xsl:for-each select="*">
       <xsl:value-of select="."/>
       <xsl:if test="position() != last()">
       <xsl:value-of select="','"/>
       </xsl:if>
       </xsl:for-each>
       <xsl:text> </xsl:text>
      </xsl:template>
      </xsl:stylesheet>


      In smooks-config if I give resource-config selector as "AssignedTaskDetails" then the result is same as the input xml.

      How should i go about this?


        • 1. Re: Problem in XML to CSV transformation
          marklittle

          Smooks has been updated to 1.0 in the SOA-P as well, but I'm not sure if that is available to free evaluators. It's certainly available to customers though.

          • 2. Re: Problem in XML to CSV transformation

            I am currently working on Evaluation version only. So what should be done to achieve the XML to CSV transformation here?

            • 3. Re: Problem in XML to CSV transformation
              marklittle

              You could get hold of the source for JBossESB 4.2.1 CP03 from the repo and build that.

              • 4. Re: Problem in XML to CSV transformation
                kconner

                You would need one of the FP tags to get the smooks 1.0 update. The CP releases are still using 0.9.

                The latest FP is FP2.

                • 5. Re: Problem in XML to CSV transformation

                  Please let me know any tutorial to perform XMT to CSV transformation using smooks and jboss-esb configuration. I'm using JBoss ESB 4.4.2GA and Smooks v1.1 .

                  • 6. Re: Problem in XML to CSV transformation

                    I tried using Neha's code for smooks-config.xml and XSLT file.
                    I used smooks filters to execute the transformation.



                    Smooks smooks = new Smooks("pdm_transformXML2CSV.xml");
                     try {
                     // Create an exec context - no profiles....
                     ExecutionContext executionContext = smooks.createExecutionContext();
                     // The result of this transform is a set of CharArray...
                     CharArrayWriter outputWriter = new CharArrayWriter();
                     // Configure the execution context to generate a report...
                     executionContext.setEventListener(new HtmlReportGenerator("report.html"));
                    
                     // Filter the input message to extract, using the execution context...
                     smooks.filter(new StreamSource(new ByteArrayInputStream(messageIn)), new StreamResult(outputWriter), executionContext);
                    
                    
                     System.out.println("***************************");
                     //System.out.println("Message Status " + pdm.getMsgHeader().getMessageStatus());
                     System.out.println("Message Header is " + outputWriter.toString());
                     System.out.println("***************************");
                     } finally {
                     smooks.close();
                     }
                    
                    


                    Everything is working fine and I'm able to get exact CSV being transformed from XML template. Thanks Neha for your code - helped me.