Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're going to need to get an instance of a <code>Transformer</code> from an appropriate <code>TransformerFactory</code>. You can use the built-in xerces transformer factory or a 3rd party XSLT processor, like <a href="http://www.saxonica.com/" rel="nofollow noreferrer">saxonica</a>.</p> <p>Using Spring's IoC you can configure a Xerces XML transformer like this:</p> <pre><code>&lt;bean id="transformerFactory" class="org.apache.xerces.jaxp.SAXParserFactoryImpl" /&gt; </code></pre> <p>or a saxon XML transformer like this:</p> <pre><code>&lt;bean id="transformerFactory" class="net.sf.saxon.TransformerFactoryImpl" /&gt; </code></pre> <p>Once you have a TransformerFactory you can use dependency injection to get a new instance of a transformer either inside your bean or using the IoC. Switching to be inside your class you might have some property, say <code>transFact</code> that you need to set:</p> <pre><code>&lt;bean id="myBean" class="myClass"&gt; &lt;property name="transFact" ref="transformerFactory" /&gt; &lt;/bean&gt; </code></pre> <p>Then in your class:</p> <pre><code>public class myClass { // ... private javax.xml.transformer.TransformerFactory transFact; public void myMethod(){ StreamSource transformerStream = new StreamSource(getResourceAsStream(pathToXslt)); javax.xml.transformer.Transformer myTrans = transFact.newTransformer(transformerStream); // now you've got a myTrans } // ... public setTransFact(javax.xml.transformer.TransformerFactory transFact){ this.transFact = transFact; } } </code></pre> <p>Alternatively you can get a new transformer within IoC using the <code>factory-method</code> with a little more effort.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload