Code example for SAXTransformerFactory

Methods: getAssociatedStylesheet, newTransformer

0
        // use system property javax.xml.transform.TransformerFactory to define special factory  (e.g. net.sf.saxon.TransformerFactoryImpl) 
        Transformer transformer = null;
        try { 
            final SAXTransformerFactory transformerFactory = (SAXTransformerFactory) TransformerFactory.newInstance();
            final Source streamSource = new StreamSource(realPath);
            final Source associatedStylesheet = transformerFactory.getAssociatedStylesheet(streamSource,
                    null, null, null); 
            if (associatedStylesheet == null) {
                return null; 
            } 
 
            transformer = transformerFactory.newTransformer(associatedStylesheet);
        } catch (TransformerConfigurationException e) {
            log.info("Can't create transformer: " + e.getMessage());//ignored
        } 
        return transformer;
    } 
 
    private XMLReader createReader() throws ParserConfigurationException, SAXException {
        final SAXParserFactory parserFactory = SAXParserFactory.newInstance();
        parserFactory.setNamespaceAware(true);