Transformer with parameters
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.xml.sax.XMLReader;
public class XMLTransform {
public static void main(String[] args) throws Exception {
System.setProperty("javax.xml.transform.TransformerFactory",
"net.sf.saxon.TransformerFactoryImpl");
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
XMLReader reader = parser.getXMLReader();
TransformerFactory factory = TransformerFactory.newInstance();
System.out.println(factory);
Transformer transformer = factory.newTransformer(new StreamSource("./xsl/books-sql.xsl"));
transformer.setParameter("user", "root");
transformer.setParameter("password", "123456");
transformer.transform(new StreamSource("./xml/books.xml"), new StreamResult(System.out));
}
}
Related examples in the same category