TemplatesParser { public Templates parseTemplates(Source source) throws TransformerConfigurationException, SAXException, IOException { InputSource inputSource = SAXSource.sourceToInputSource(source); if (inputSource == null) { throw new RuntimeException("Unable convert to Input Source"); } SAXTransformerFactory saxTransformerFactory = createFeaturedSaxTransformerFactory(); TemplatesHandler templateHandler = saxTransformerFactory.newTemplatesHandler(); XMLReader xmlReader = XMLReaderFactory.createXMLReader(); if (resolver != null) { xmlReader.setEntityResolver(resolver); } xmlReader.setContentHandler(templateHandler); xmlReader.parse(inputSource); Templates templates = templateHandler.getTemplates(); if (templates == null) { throw new RuntimeException("Unable create templates from given source"); } return templates; }  void setResolver(EntityResolver resolver); Templates parseTemplates(Source source);  }
@Test public void parsesGivenSourceToTemplates() throws Exception { try (InputStream testXslResource = Thread.currentThread().getContextClassLoader().getResourceAsStream("xslt/book.xsl")) { Source source = new StreamSource(testXslResource); Templates templates = templatesParser.parseTemplates(source); assertNotNull(templates); } }