public void genericTransform(XdmNode input, Map<String, Object> parameters, Destination dest) throws SaxonApiException { if (parameters != null) { for (Map.Entry<String, Object> param : parameters.entrySet()) { this.transformer.setParameter(new QName(null, param.getKey()), new XdmAtomicValue(param.getValue().toString())); } } this.transformer.setSource(input.asSource()); this.transformer.setDestination(dest); this.transformer.transform(); if (parameters != null) { //cancel the parameters for (Map.Entry<String, Object> param : parameters.entrySet()) { this.transformer.setParameter(new QName(null, param.getKey()), null); } } }
XsltExecutable exec = compiler.compile(xslt); XsltTransformer transformer = exec.load(); transformer.setSource(new DOMSource(sourceDoc)); transformer.setDestination(new DOMDestination(resultDoc)); transformer.transform();
XsltExecutable exec = compiler.compile(xslt); XsltTransformer transformer = exec.load(); transformer.setSource(new DOMSource(sourceDoc)); transformer.setDestination(new DOMDestination(resultDoc)); transformer.transform();
private List<File> convertFiles(List<File> filesToLoad) throws ServletException { List<File> rdfxmlFiles = new ArrayList<File>(filesToLoad.size()); for( File file: filesToLoad){ try { //look for an example of this in S9APIExamples.java from saxon he 9 XsltTransformer t = xsltExec.load(); //this is how to set parameters: //t.setParameter(new QName("someparametername"), new XdmAtomicValue(10)); Serializer out = new Processor(false).newSerializer(); out.setOutputProperty(Serializer.Property.METHOD, "xml"); out.setOutputProperty(Serializer.Property.INDENT, "yes"); File outFile = new File(file.getAbsolutePath() + ".rdfxml"); rdfxmlFiles.add(outFile); out.setOutputFile(outFile); t.setSource(new StreamSource(file)); t.setDestination(out); t.transform(); } catch (SaxonApiException e) { log.error("could not convert " + file.getAbsolutePath() + " to RDF/XML: " + e.getMessage()); throw new ServletException("could not convert " + file.getAbsolutePath() + " to RDF/XML: " + e.getMessage()); } } return rdfxmlFiles; }
XsltExecutable exec = compiler.compile(xslt); XsltTransformer transformer = exec.load(); transformer.setSource(new DOMSource(sourceDoc)); transformer.setDestination(new DOMDestination(resultDoc)); transformer.transform();
XsltExecutable exec = compiler.compile(xslt); XsltTransformer transformer = exec.load(); transformer.setSource(new DOMSource(sourceDoc)); transformer.setDestination(new DOMDestination(resultDoc)); transformer.transform();
trans.setSource(content);
/** * Check conformance to TAXII specification beyond what XML Schema provides. */ private void checkConformance(Object m, ValidationErrorHandler errorHandler) { final XsltTransformer transformer = schematronValidator.load(); transformer.setMessageListener(errorHandler); try { transformer.setSource(new JAXBSource(jaxbContext, m)); transformer.setDestination(new SAXDestination(new DefaultHandler())); transformer.transform(); } catch (SaxonApiException | JAXBException e) { errorHandler.getResults().addError("Conformance error: " + e.getMessage()); } }
/** * Transforms a standard SVRL report to a plain text representation that * only includes rule violations (positive or negative assertion failures). * * @param svrlSource * The source for reading the SVRL report. * @return A StreamResult holding the plain text output (as a byte stream), * or null if the transformation failed. */ StreamResult generateTextResult(Source svrlSource) { XsltCompiler compiler = processor.newXsltCompiler(); StreamResult result = null; try { XsltExecutable exec = compiler.compile(new StreamSource(getClass().getResourceAsStream("svrl2text.xsl"))); XsltTransformer transformer = exec.load(); transformer.setSource(svrlSource); Serializer serializer = new Serializer(); serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); serializer.setOutputStream(bos); transformer.setDestination(serializer); transformer.transform(); result = new StreamResult(bos); } catch (SaxonApiException e) { LOGR.warning(e.getMessage()); } return result; }
public static Reader applyEventStylesheet(Binary binary, boolean onlyDetails, Map<String, String> translations, String path) throws GenericException { try ( Reader descMetadataReader = new InputStreamReader(new BOMInputStream(binary.getContent().createInputStream()))) { XMLReader xmlReader = XMLReaderFactory.createXMLReader(); xmlReader.setEntityResolver(new RodaEntityResolver()); InputSource source = new InputSource(descMetadataReader); Source text = new SAXSource(xmlReader, source); XsltExecutable xsltExecutable = EVENT_CACHE.get(path); XsltTransformer transformer = xsltExecutable.load(); CharArrayWriter transformerResult = new CharArrayWriter(); transformer.setSource(text); transformer.setDestination(PROCESSOR.newSerializer(transformerResult)); // send param to filter stylesheet work transformer.setParameter(new QName("onlyDetails"), new XdmAtomicValue(Boolean.toString(onlyDetails))); for (Entry<String, String> parameter : translations.entrySet()) { QName qName = new QName(parameter.getKey()); XdmValue xdmValue = new XdmAtomicValue(parameter.getValue()); transformer.setParameter(qName, xdmValue); } transformer.transform(); return new CharArrayReader(transformerResult.toCharArray()); } catch (IOException | SAXException | ExecutionException | SaxonApiException e) { LOGGER.error(e.getMessage(), e); throw new GenericException("Could not process event binary " + binary.getStoragePath(), e); } }
public static Reader applyMetadataStylesheet(Binary binary, String basePath, String metadataType, String metadataVersion, Map<String, String> parameters) throws GenericException { try ( Reader descMetadataReader = new InputStreamReader(new BOMInputStream(binary.getContent().createInputStream()))) { XMLReader xmlReader = XMLReaderFactory.createXMLReader(); xmlReader.setEntityResolver(new RodaEntityResolver()); InputSource source = new InputSource(descMetadataReader); Source text = new SAXSource(xmlReader, source); XsltExecutable xsltExecutable = CACHE.get(Triple.of(basePath, metadataType, metadataVersion)); XsltTransformer transformer = xsltExecutable.load(); CharArrayWriter transformerResult = new CharArrayWriter(); transformer.setSource(text); transformer.setDestination(PROCESSOR.newSerializer(transformerResult)); for (Entry<String, String> parameter : parameters.entrySet()) { QName qName = new QName(parameter.getKey()); XdmValue xdmValue = new XdmAtomicValue(parameter.getValue()); transformer.setParameter(qName, xdmValue); } transformer.transform(); return new CharArrayReader(transformerResult.toCharArray()); } catch (IOException | SAXException | ExecutionException | SaxonApiException e) { throw new GenericException("Could not process descriptive metadata binary " + binary.getStoragePath() + " metadata type " + metadataType + " and version " + metadataVersion, e); } }
generatorTransformer.setSource(ctlSource); Serializer generatorSerializer = new Serializer(); generatorSerializer.setOutputFile(indexFile);
XdmDestination results = new XdmDestination(); try { transformer.setSource(xmlSource); transformer.setDestination(results); transformer.transform();
XsltTransformer stage2Transformer = abstractXslt.load(); XsltTransformer stage3Transformer = svrlXslt.load(); stage1Transformer.setSource(schema); stage1Transformer.setDestination(stage2Transformer); stage2Transformer.setDestination(stage3Transformer);
transformer.setSource(node); transformer.setErrorListener(eval.getErrorListener()); if (arguments.length > 2) {
xspecCompiler.setSource(testAsSource); xspecCompiler.setDestination(xspecTestCompiled); xspecCompiler.setErrorListener(saxonReporter); XsltTransformer htmlFormatter = xspecHtmlFormatterLoader.load(); htmlFormatter .setSource(xspecTestResult.getXdmNode().asSource()); htmlFormatter.setParameter(XSPEC_CSS_URI_PARAM, XSPEC_CSS_URI); htmlFormatter.setDestination(serializeToFile(htmlReport)); XsltTransformer junitFormatter = xspecJUnitFormatterLoader .load(); junitFormatter.setSource(xspecTestResult.getXdmNode() .asSource()); junitFormatter.setDestination(serializeToFile(surefireReport));
public void transform(Source xmlSource, final Result outputTarget) throws XPathException { try { xsltTransformer.setSource(xmlSource); if (outputTarget.getSystemId() != null) { //bug 2214 xsltTransformer.setBaseOutputURI(outputTarget.getSystemId());
public void transform(Source xmlSource, final Result outputTarget) throws XPathException { try { xsltTransformer.setSource(xmlSource); if (outputTarget.getSystemId() != null) { //bug 2214 xsltTransformer.setBaseOutputURI(outputTarget.getSystemId());