How can i configure java.xml.transform.Transformer in spring framework ? I need instance of transformer to transform xml to text via xslt. Hence it is critical that the configured transformer should have knowledge of xslt stylesheet. I am not using this in a web project, rather i am using this in a standalone java program.
Well, the Java to configure a Transformer is like this:
Source stylesheetSource = new StreamSource(new File("/path/to/my/stylesheet.xslt"));
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer(stylesheetSource);
If you really want to do this purely in Spring XML, this is the equivalent:
<bean id="stylesheetSource" class="javax.xml.transform.stream.StreamSource">
<property name="systemId" value="/path/to/my/stylesheet.xslt"/>
</bean>
<bean id="transformerFactory" class="javax.xml.transform.TransformerFactory" factory-method="newInstance"/>
<bean id="transformer" factory-bean="transformerFactory" factory-method="newTransformer">
<constructor-arg ref="stylesheetSource"/>
</bean>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With