How to add XSL resource dynamically (programatically) in xslt-transformer?
<p>I am using spring integration's <strong>xslt-transfomer</strong> for xml transformation.
My code is like below, </p>

<pre><code>&lt;int-xml:xslt-transformer id="xmlTransformer" input-channel="inputChannel" 
        output-channel="outputChannel"  xsl-resource="classpath:META-INF/OrderXslt.xsl" /&gt;
</code></pre>

<p>here I want to pass <strong>xsl-resource="classpath:META-INF/OrderXslt.xsl"</strong> dynamically at the runtime. I am able to get <strong>xmlTransformer</strong> bean from context but cant figure out how to set <strong>xsl-resource</strong> to it. My java code is like, </p>

<pre><code>File myFile = new File("D:\OrderXslt.xsl");
EventDrivenConsumer transformerConsumer =  (EventDrivenConsumer) ctx.getBean("xmlTransformer");

//I need to pass myFile to transformerConsumer instace.
//However I am unable to find any API of EventDrivenConsumer 
            which will accept xsl resource form here (i.e. myFile )
</code></pre>

<p>Any programmatic explanation will be highly appreciated.
Thanks in advance.</p>

<p><strong>EDIT</strong></p>

<pre><code>    public class TempTransformer&lt;Object, Obejct&gt; extends AbstractTransformer  {

    private volatile XsltPayloadTransformer xslt;

    protected Object doTransform(Message&lt;?&gt; message) throws Exception {
        return (Object) findorBuildTransformerForMessage(message).transform(message); 
//Its throwing error here as
//org.springframework.integration.transformer.MessageTransformationException: failed to transform message; nested exception is java.lang.NullPointerException
    }

    private Transformer findorBuildTransformerForMessage(Message&lt;?&gt; message{
    xslt = new XsltPayloadTransformer(new ClassPathResource("/META-INF/OrderXslt2.xsl"));
    return xslt;
    }
</code></pre>

<p><strong>EDIT</strong></p>

<p>I have implemented <code>XsltPayloadTransformer</code> the in the following way.</p>

<pre><code>protected Message&lt;?&gt; doTransform(Message&lt;?&gt; message) throws Exception {
    xsltTransformer = new XsltPayloadTransformer(new ClassPathResource("D:/sample.xsl"));

    this.xsltTransformer.setResultType("StringResult");
    this.xsltTransformer.afterPropertiesSet();
    return this.xsltTransformer.transform(message);

    }
</code></pre>

<p>However I am not getting correct output. On the other hand I have a simple java program which uses Saxon implementation and shows correct output. Here it is... </p>

<pre><code> public static void main(String [] arr) {

    TransformerFactory tFactory = TransformerFactory.newInstance();
    StreamSource xmlInputFile = new StreamSource("D:/input.xml");
    StreamSource xslTransformationFile = new StreamSource("D:/sample.xsl");
    StreamResult xmlOutputFile = new StreamResult(new File("D:/output.xml"));
    Transformer transformer;
    try {
        transformer = tFactory.newTransformer(xslTransformationFile);  //gives instance of net.sf.saxon.jaxp.TransformerImpl 
        transformer.transform(xmlInputFile, xmlOutputFile);
    } 
    } catch (Exception e) {

    }

    }
</code></pre>

<p>I cant figure out what I am missing. Is there anything else I need to set to <code>XsltPayloadTransformer</code>?? Or I am missing on anything ?
 I am using <strong>XSL v2</strong> and <strong>spring 4.1.7</strong> and <strong>spring integration 4.1.8</strong> vesrions.</p>