public CompiledStylesheet compileStylesheet(InputStream stylesheet) throws SaxonApiException { CompiledStylesheet cs = new CompiledStylesheet(this.xsltCompiler .compile(new StreamSource(stylesheet))); if (this.uriResolver != null) cs.setURIResolver(this.uriResolver); return cs; }
protected static XsltExecutable createEventTransformer(String path) throws SaxonApiException, GenericException { try (InputStream transformerStream = RodaCoreFactory.getConfigurationFileAsStream(path)) { if (transformerStream == null) { throw new GenericException("Could not find stylesheet nor fallback at path=" + path); } XsltCompiler compiler = PROCESSOR.newXsltCompiler(); compiler.setURIResolver(new RodaURIFileResolver()); return compiler.compile(new StreamSource(transformerStream)); } catch (IOException e) { throw new GenericException(e); } }
/** * Compiles an xsl file. * @param inputStream the xsl file as {@link InputStream} * @param processor the {@link Processor} that provides the compiler * @return an {@link XsltExecutable} that will be used further in the xsl transformation process * @throws SaxonApiException it is thrown if an exception occurs during the compilation */ public XsltExecutable compileXsl(final InputStream inputStream, final Processor processor) throws SaxonApiException { XsltCompiler xsltCompiler = processor.newXsltCompiler(); Source xslSource = streamSourceFactory.createStreamSource(inputStream); xsltCompiler.setErrorListener(errorListener); XsltExecutable xsltExecutable = xsltCompiler.compile(xslSource); return xsltExecutable; }
private XdmNode transform(XdmNode source, SAXSource stylesheet) throws SaxonApiException { XsltCompiler compiler = runtime.getProcessor().newXsltCompiler(); compiler.setSchemaAware(schemaAware); compiler.setURIResolver(new UResolver()); XsltExecutable exec = compiler.compile(stylesheet); XsltTransformer schemaCompiler = exec.load(); schemaCompiler.setInitialContextNode(source); XdmDestination result = new XdmDestination(); schemaCompiler.setDestination(result); schemaCompiler.transform(); return result.getXdmNode(); }
final ErrorListener originalListener = xsltCompiler.getErrorListener(); xsltCompiler.setErrorListener(new ErrorListener() { @Override public void warning(TransformerException exception) throws TransformerException { try { String base = getStaticBaseUriString(); style = xsltCompiler.getURIResolver().resolve(stylesheetLocation, base); style = xsltCompiler.getProcessor().getUnderlyingConfiguration().getSystemURIResolver().resolve(stylesheetLocation, base); executable = xsltCompiler.compile(style); } catch (SaxonApiException e) { return reportCompileError(e, compileErrors); executable = xsltCompiler.compile(source); } catch (SaxonApiException e) { reportCompileError(e, compileErrors); executable = xsltCompiler.compile(style); } catch (SaxonApiException e) { reportCompileError(e, compileErrors); XsltPackage pack = xsltCompiler.obtainPackage(packageName, packageVersion); if (pack == null) { throw new XPathException("Cannot locate package " + packageName + " version " + packageVersion, "FOXT0002");
compiler.setErrorListener(new DefaultErrorListener()); compiler.setCompileWithTracing(isTracing); String version = getConfigs().getString(config, "languageVersion", null); if (version != null) { compiler.setXsltLanguageVersion(version); String query = getConfigs().getString(fragment, "queryString", null); if (query != null) { executable = compiler.compile(new StreamSource(new StringReader(query))); executable = compiler.compile(new StreamSource(new File(queryFile)));
processor.setConfigurationProperty(Feature.TRACE_OPTIMIZER_DECISIONS, true); jit = false; compiler.setJustInTimeCompilation(jit); if (!"".equals(value)) { explainOutputFileName = value; export = true; jit = false; compiler.setJustInTimeCompilation(jit); if (!"".equals(value)) { exportOutputFileName = value; compiler.setTargetEdition(value); compiler.setRelocatable(true); compiler.setJustInTimeCompilation(jit); lib = new PackageLibrary(compiler.getUnderlyingCompilerInfo(), packs); } catch (XPathException e) { quit(e.getMessage(), 2); compiler.getUnderlyingCompilerInfo().setPackageLibrary(lib); compiler.setJustInTimeCompilation(false); processor.setConfigurationProperty(Feature.TRACE_LISTENER, traceListener); processor.setConfigurationProperty(Feature.LINE_NUMBERING, true); compiler.getUnderlyingCompilerInfo().setCodeInjector(new TimingCodeInjector());
xsltCompiler.setURIResolver(new XSpecResolver(xsltCompiler .getURIResolver())); .compile(getXSpecSource("/xspec/compiler/generate-xspec-tests.xsl")); .compile(getXSpecSource("/xspec/reporter/format-xspec-report.xsl")); .compile(getXSpecSource("/xspec-extra/format-xspec-summary.xsl")); .compile(getXSpecSource("/xspec-extra/format-junit-report.xsl"));
compiler.setSchemaAware(false); XsltExecutable exec = compiler.compile(new SAXSource(new InputSource(xsl))); XsltTransformer transformer = exec.load(); transformer.setInitialContextNode(profile);
/** * Process the Source into a Templates object, which is a * a compiled representation of the source. This Templates object * may then be used concurrently across multiple threads. Creating * a Templates object allows the TransformerFactory to do detailed * performance optimization of transformation instructions, without * penalizing runtime transformation. * * @param source An object that holds a URL, input stream, etc. * @param info compile-time options for this stylesheet compilation * @return A Templates object capable of being used for transformation purposes, * never null. * @throws javax.xml.transform.TransformerConfigurationException * May throw this during the parse when it * is constructing the Templates object and fails. */ public Templates newTemplates(Source source, CompilerInfo info) throws TransformerConfigurationException { try { XsltCompiler compiler = processor.newXsltCompiler(); compiler.getUnderlyingCompilerInfo().copyFrom(info); return new TemplatesImpl(compiler.compile(source)); } catch (SaxonApiException e) { throw new TransformerConfigurationException(e); } }
Source style = compiler.getAssociatedStylesheet(sourceDoc.asSource(), null, null, null); XsltExecutable sheet = compiler.compile(style);
try { XsltCompiler compiler = runtime.getProcessor().newXsltCompiler(); compiler.setSchemaAware(processor.isSchemaAware()); compiler.setErrorListener(new LogCompileErrors()); XsltExecutable exec = compiler.compile(stylesheet.asSource()); XsltTransformer transformer = exec.load();
xsltCompiler.setURIResolver(context.getURIResolver()); xsltCompiler.setJustInTimeCompilation(false);
private void initCompiler(Configuration config) { this.xsltCompiler = new Processor(config).newXsltCompiler(); if (this.uriResolver != null) { //this resolver is used for xsl:include and xsl:import this.xsltCompiler.setURIResolver(this.uriResolver); } } }
/** * Create an XsltCompiler. An XsltCompiler is used to compile XSLT stylesheets. * * @return a newly created XsltCompiler * @throws UnsupportedOperationException if this version of the Saxon product does not support XSLT processing */ /*@NotNull*/ public XsltCompiler newXsltCompiler() { return new XsltCompiler(this); }
private XdmNode transform(XdmNode source, SAXSource stylesheet) throws SaxonApiException { XsltCompiler compiler = runtime.getProcessor().newXsltCompiler(); compiler.setSchemaAware(schemaAware); compiler.setURIResolver(new UResolver()); XsltExecutable exec = compiler.compile(stylesheet); XsltTransformer schemaCompiler = exec.load(); schemaCompiler.setInitialContextNode(source); XdmDestination result = new XdmDestination(); schemaCompiler.setDestination(result); schemaCompiler.transform(); return result.getXdmNode(); }
final ErrorListener originalListener = xsltCompiler.getErrorListener(); xsltCompiler.setErrorListener(new ErrorListener() { @Override public void warning(TransformerException exception) throws TransformerException { try { String base = getStaticBaseUriString(); style = xsltCompiler.getURIResolver().resolve(stylesheetLocation, base); style = xsltCompiler.getProcessor().getUnderlyingConfiguration().getSystemURIResolver().resolve(stylesheetLocation, base); executable = xsltCompiler.compile(style); } catch (SaxonApiException e) { return reportCompileError(e, compileErrors); executable = xsltCompiler.compile(source); } catch (SaxonApiException e) { reportCompileError(e, compileErrors); executable = xsltCompiler.compile(style); } catch (SaxonApiException e) { reportCompileError(e, compileErrors); XsltPackage pack = xsltCompiler.obtainPackage(packageName, packageVersion); if (pack == null) { throw new XPathException("Cannot locate package " + packageName + " version " + packageVersion, "FOXT0002");
compiler.setErrorListener(new DefaultErrorListener()); compiler.setCompileWithTracing(isTracing); String version = getConfigs().getString(config, "languageVersion", null); if (version != null) { compiler.setXsltLanguageVersion(version); String query = getConfigs().getString(fragment, "queryString", null); if (query != null) { executable = compiler.compile(new StreamSource(new StringReader(query))); executable = compiler.compile(new StreamSource(new File(queryFile)));
processor.setConfigurationProperty(Feature.TRACE_OPTIMIZER_DECISIONS, true); jit = false; compiler.setJustInTimeCompilation(jit); if (!"".equals(value)) { explainOutputFileName = value; export = true; jit = false; compiler.setJustInTimeCompilation(jit); if (!"".equals(value)) { exportOutputFileName = value; compiler.setTargetEdition(value); compiler.setRelocatable(true); compiler.setJustInTimeCompilation(jit); lib = new PackageLibrary(compiler.getUnderlyingCompilerInfo(), packs); } catch (XPathException e) { quit(e.getMessage(), 2); compiler.getUnderlyingCompilerInfo().setPackageLibrary(lib); compiler.setJustInTimeCompilation(false); processor.setConfigurationProperty(Feature.TRACE_LISTENER, traceListener); processor.setConfigurationProperty(Feature.LINE_NUMBERING, true); compiler.getUnderlyingCompilerInfo().setCodeInjector(new TimingCodeInjector());
compiler.setSchemaAware(false); XsltExecutable exec = compiler.compile(new SAXSource(new InputSource(xsl))); XsltTransformer transformer = exec.load(); transformer.setInitialContextNode(profile);