sonum kumar
sonum kumar

Reputation: 183

XSLT processing with Xalan APi 2.7.1

I have to do xsl transformations in which I will pass the sample input xml to finally achieved the final transformation xml , I have written the program using java api of a transformer , can some body please advise how canI write the same so that it works with xalan api 2.7.1 also , below is the code with jaa which I need to convert it with xalan compatible

import javax.xml.transform.*;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;

public class TestMain {
    public static void main(String[] args) throws IOException, URISyntaxException, TransformerException {
        TransformerFactory factory = TransformerFactory.newInstance();
        Source xslt = new StreamSource(new File("transform.xslt"));
        Transformer transformer = factory.newTransformer(xslt);

        Source text = new StreamSource(new File("input.xml"));
        transformer.transform(text, new StreamResult(new File("output.xml")));
    }
} 

Upvotes: 0

Views: 1272

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122364

The API you need to use for Xalan is the standard javax.xml.transform API, there's nothing to change. If Xalan is on your application's classpath then

TransformerFactory.newInstance();

will create a Xalan transformer rather than using the Java built-in implementation (which is itself a fork of Xalan). If you want to force a particular transformer implementation then use the two-argument form

TransformerFactory.newInstance("org.apache.xalan.processor.TransformerFactoryImpl", null);

Upvotes: 1

Related Questions