本文整理汇总了Java中net.sf.saxon.s9api.Processor.newXsltCompiler方法的典型用法代码示例。如果您正苦于以下问题:Java Processor.newXsltCompiler方法的具体用法?Java Processor.newXsltCompiler怎么用?Java Processor.newXsltCompiler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.saxon.s9api.Processor
的用法示例。
在下文中一共展示了Processor.newXsltCompiler方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compileXsl
import net.sf.saxon.s9api.Processor; //导入方法依赖的package包/类
/**
* 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;
}
示例2: transform
import net.sf.saxon.s9api.Processor; //导入方法依赖的package包/类
/**
* Transforms the content of a DOM Node using a specified XSLT stylesheet.
*
* @param xslt
* A Source object representing a stylesheet (XSLT 1.0 or 2.0).
* @param source
* A Node representing the XML source. If it is an Element node
* it will be imported into a new DOM Document.
* @return A DOM Document containing the result of the transformation.
*/
public static Document transform(Source xslt, Node source) {
Document sourceDoc = null;
Document resultDoc = null;
try {
resultDoc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().newDocument();
if (source.getNodeType() == Node.DOCUMENT_NODE) {
sourceDoc = (Document) source;
} else {
sourceDoc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().newDocument();
sourceDoc.appendChild(sourceDoc.importNode(source, true));
}
} catch (ParserConfigurationException pce) {
throw new RuntimeException(pce);
}
Processor processor = new Processor(false);
XsltCompiler compiler = processor.newXsltCompiler();
try {
XsltExecutable exec = compiler.compile(xslt);
XsltTransformer transformer = exec.load();
transformer.setSource(new DOMSource(sourceDoc));
transformer.setDestination(new DOMDestination(resultDoc));
transformer.transform();
} catch (SaxonApiException e) {
throw new RuntimeException(e);
}
return resultDoc;
}
示例3: Engine
import net.sf.saxon.s9api.Processor; //导入方法依赖的package包/类
public Engine() throws Exception {
String s = System.getProperty("te.cacheSize");
if (s != null) {
cacheSize = Integer.parseInt(s);
}
// Create processor
processor = new Processor(false);
// Modify its configuration settings
Configuration config = processor.getUnderlyingConfiguration();
config.setVersionWarning(false);
// Use our custom error listener which reports line numbers in the CTL
// source file
errorListener = new TeErrorListener();
config.setErrorListener(errorListener);
// Create a compiler and document builder
compiler = processor.newXsltCompiler();
builder = processor.newDocumentBuilder();
// Load an executable for the TECore.form method
ClassLoader cl = Thread.currentThread().getContextClassLoader();
InputStream is = cl.getResourceAsStream("com/occamlab/te/formfn.xsl");
formExecutable = compiler.compile(new StreamSource(is));
}