Announcement Announcement Module
Collapse
No announcement yet.
Use of XsltPayloadTransformer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Use of XsltPayloadTransformer

    Hi !

    I use yesterday's trunk version and tried

    Code:
    <message-bus />
    
    <file:inbound-channel-adapter id="inputChannel"
    	directory="file:C:/input">
    	<poller>
    		<interval-trigger interval="1000" />
    	</poller>
    </file:inbound-channel-adapter>
    
    <file:outbound-channel-adapter id="outputChannel" directory="C:/output" />
    
    <si-xml:xslt-transformer input-channel="inputChannel" 
    xsl-resource="file:C:/test.xslt" output-channel="outputChannel" />
    with test.xslt :
    Code:
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    	<xsl:output method="text"/>
    	<xsl:template match="/person">
    		<xsl:value-of select="name"/>
    	</xsl:template>
    </xsl:stylesheet>
    and test.xml in the input directory :
    Code:
    <?xml version="1.0"?>
    <persons>
    	<person>
    		<name>John</name>
    		<family-name>Smith</family-name>
    	</person>
    </persons>
    The test.xml input file is read but i have nothing in the output directory and no visible error/exception.

    Where I am wrong ?

    Thank you for your help !
    Last edited by OsoPardo; Oct 21st, 2008, 09:54 AM.

  • #2
    There are a few problems here. If you increase the logging level you should see with your current configuration that the message was being rejected by the Xslt transformer with an error message "Failed to create Source for payload type java.io.File" since it did not know what to do with the payload. The message was then added to the default error channel. Currently the Xslt transformer supports Source, String and Document payloads. The file inbound channel adapter by default passes a File instance as the payload hence the Xslt transformer was rejecting the message.

    The below configuration addresses this by using an instance of file-to-string-transformer before passing the message to the Xslt transformer.

    In addition the Xslt transformer will by default return a Result instance so the below configuration also adds a result transformer to convert the output of the Xslt to a String so it can then be correctly written to the output file.

    Code:
    <si:message-bus />
    
    <si:channel id="tranformChannel" />
    
    <file:inbound-channel-adapter id="inputChannel" directory="file:./input">
    	<si:poller>
    		<si:interval-trigger interval="1000" />
    	</si:poller>
    </file:inbound-channel-adapter>
    
    
    <file:file-to-string-transformer id="toStringTransformer" input-channel="inputChannel" output-channel="transformChannel"/>
    
    <file:outbound-channel-adapter id="outputChannel" directory="./output" />
    
    <si-xml:xslt-transformer input-channel="transformChannel" xsl-resource="classpath:test.xslt" output-channel="outputChannel" result-transformer="resultTransformer" />
    		
    		
    <bean id="resultTransformer" class="org.springframework.integration.xml.transformer.ResultToStringTransformer" />

    Comment


    • #3
      Thank you !

      Just to inform, that's require the library spring-xml-1.5.3.jar from Spring Web Service.

      Comment


      • #4
        Originally posted by JonasPartner View Post
        There are a few problems here. If you increase the logging level you should see with your current configuration that the message was being rejected by the Xslt transformer with an error message "Failed to create Source for payload type java.io.File" since it did not know what to do with the payload. The message was then added to the default error channel. Currently the Xslt transformer supports Source, String and Document payloads. The file inbound channel adapter by default passes a File instance as the payload hence the Xslt transformer was rejecting the message.

        The below configuration addresses this by using an instance of file-to-string-transformer before passing the message to the Xslt transformer.

        In addition the Xslt transformer will by default return a Result instance so the below configuration also adds a result transformer to convert the output of the Xslt to a String so it can then be correctly written to the output file.

        Code:
        <si:message-bus />
        
        <si:channel id="tranformChannel" />
        
        <file:inbound-channel-adapter id="inputChannel" directory="file:./input">
        	<si:poller>
        		<si:interval-trigger interval="1000" />
        	</si:poller>
        </file:inbound-channel-adapter>
        
        
        <file:file-to-string-transformer id="toStringTransformer" input-channel="inputChannel" output-channel="transformChannel"/>
        
        <file:outbound-channel-adapter id="outputChannel" directory="./output" />
        
        <si-xml:xslt-transformer input-channel="transformChannel" xsl-resource="classpath:test.xslt" output-channel="outputChannel" result-transformer="resultTransformer" />
        		
        		
        <bean id="resultTransformer" class="org.springframework.integration.xml.transformer.ResultToStringTransformer" />

        Hi I am new member to Spring Source. Firstoff all hello to every members..
        Now my question is that ..How to run this from a test class by passing an XML..Please provide the complete code..

        Comment


        • #5
          Hi,
          How can I test this fuctionality using an test case.simple from a java main function..Plz provide the complete code..

          Comment


          • #6
            You cant pass in the XML via a main method, it's a file inbound adapter polling a directory.

            In the main method you just need to load the application context.

            Code:
            public static void main(String[] args) {
            		new ClassPathXmlApplicationContext("applicationContext.xml", SpringIntegrationDemo.class);
            	}
            Then put a file containing the XML in the directory being polled. In this case ./input In order to run this example you'll also need to create the XSTL too.

            Comment


            • #7
              Actualy I need to transform using XSL, an input XML ie to be generated at runtime and and to get an output XML of another format..by using Spring Integration(using XSLpayload transformer in Spring Integration ). So can you tell me the whole process how to send an input XMl file and get an Output XML file.
              Please provide me the whole code.ie how I need to do the configuration in App-Context.xml andusing the testclass to do the test.

              Comment


              • #8
                You should have a look at the XML sample included in the distribution. That includes an XsltTransformer.

                Comment

                Working...
                X