本文整理汇总了Java中net.sf.saxon.s9api.XsltTransformer.setDestination方法的典型用法代码示例。如果您正苦于以下问题:Java XsltTransformer.setDestination方法的具体用法?Java XsltTransformer.setDestination怎么用?Java XsltTransformer.setDestination使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.saxon.s9api.XsltTransformer
的用法示例。
在下文中一共展示了XsltTransformer.setDestination方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractString
import net.sf.saxon.s9api.XsltTransformer; //导入方法依赖的package包/类
private String extractString(SaxonNodeWrapper node, String xslUrl) {
try {
final XsltExecutable executable = bookCache.getExtractTransformerCache().getExecutable(new URL(bookCache.getDitaOtUrl(), xslUrl));
final XsltTransformer xsltTransformer = executable.load();
xsltTransformer.setInitialContextNode(new XdmNode(node.getNodeInfo()));
final XdmDestination destination = new XdmDestination();
xsltTransformer.setDestination(destination);
xsltTransformer.transform();
return destination.getXdmNode().getStringValue();
} catch (Exception e) {
logger.error(e, e);
return "<ERR>";
}
}
示例2: doProcess2
import net.sf.saxon.s9api.XsltTransformer; //导入方法依赖的package包/类
@Override
protected boolean doProcess2(Record inputRecord, InputStream stream) throws SaxonApiException, XMLStreamException {
incrementNumRecords();
for (Fragment fragment : fragments) {
Record outputRecord = inputRecord.copy();
removeAttachments(outputRecord);
XdmNode document = parseXmlDocument(stream);
LOG.trace("XSLT input document: {}", document);
XsltTransformer evaluator = fragment.transformer;
evaluator.setInitialContextNode(document);
XMLStreamWriter morphlineWriter = new MorphlineXMLStreamWriter(getChild(), outputRecord);
evaluator.setDestination(new XMLStreamWriterDestination(morphlineWriter));
evaluator.transform(); // run the query and push into child via RecordXMLStreamWriter
}
return true;
}
示例3: doTest
import net.sf.saxon.s9api.XsltTransformer; //导入方法依赖的package包/类
@Test
public void doTest() throws SaxonApiException, FileNotFoundException, IOException {
Configuration config = Configuration.newConfiguration();
Processor processor = new Processor(config);
XsltTransformer transformer = processor.newXsltCompiler().compile(new StreamSource("src/test/resources/identity.xsl")).load();
Serializer serializer = processor.newSerializer(new File("target/generated-test-files/output.xml"));
FileAppenderStep fas = new FileAppenderStep();
fas.setParameter(FileAppenderStep.FILE_NAME, new XdmAtomicValue("target/generated-test-files/appendee.txt"));
fas.setParameter(FileAppenderStep.VALUE, new XdmAtomicValue("blablabla"));
fas.setParameter(FileAppenderStep.LINE_SEPARATOR, new XdmAtomicValue("LF"));
fas.setDestination(serializer);
transformer.setDestination(fas);
transformer.setSource(new StreamSource("src/test/resources/source.xml"));
File expect = new File("target/generated-test-files/appendee.txt");
if(expect.exists()) expect.delete();
transformer.transform();
assertTrue(expect.isFile());
BufferedReader br = new BufferedReader(new FileReader(expect));
char[] buff = new char[30];
int ret = br.read(buff);
br.close();
assertEquals(10, ret);
char[] ex = new char[] { 'b', 'l', 'a', 'b', 'l', 'a', 'b', 'l', 'a', '\n'};
assertArrayEquals(ex, Arrays.copyOf(buff, ret));
fas.setDestination(processor.newSerializer(new File("target/generated-test-files/output2.xml")));
transformer.transform();
br = new BufferedReader(new FileReader(expect));
ret = br.read(buff);
br.close();
assertEquals(20, ret);
}
示例4: getOutput
import net.sf.saxon.s9api.XsltTransformer; //导入方法依赖的package包/类
/** Retrieves the output for a given xslt transformer.
* @param xsltTransformer the {@link XsltTransformer} that will receive the output
* @return the output as a {@link ByteArrayOutputStream}
*/
public ByteArrayOutputStream getOutput(final XsltTransformer xsltTransformer) {
Serializer serializer = serializerFactory.createSerializer();
serializer.setOutputProperty(Serializer.Property.METHOD, "xml");
serializer.setOutputProperty(Serializer.Property.INDENT, "no");
ByteArrayOutputStream output = byteArrayOutputStreamFactory.createByteArrayOutputStream();
serializer.setOutputStream(output);
xsltTransformer.setDestination(serializer);
return output;
}
示例5: transform
import net.sf.saxon.s9api.XsltTransformer; //导入方法依赖的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;
}
示例6: checkConformance
import net.sf.saxon.s9api.XsltTransformer; //导入方法依赖的package包/类
/**
* 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());
}
}
示例7: executeTemplate
import net.sf.saxon.s9api.XsltTransformer; //导入方法依赖的package包/类
public XdmNode executeTemplate(TemplateEntry template, XdmNode params,
XPathContext context) throws Exception {
if (stop) {
throw new Exception("Execution was stopped by the user.");
}
XsltExecutable executable = engine.loadExecutable(template,
opts.getSourcesName());
XsltTransformer xt = executable.load();
XdmDestination dest = new XdmDestination();
xt.setDestination(dest);
if (template.usesContext() && context != null) {
xt.setSource((NodeInfo) context.getContextItem());
} else {
xt.setSource(new StreamSource(new StringReader("<nil/>")));
}
xt.setParameter(TECORE_QNAME, new ObjValue(this));
if (params != null) {
xt.setParameter(TEPARAMS_QNAME, params);
}
// test may set global verdict, e.g. by calling ctl:fail
if (LOGR.isLoggable( FINE)) {
LOGR.log( FINE,
"Executing TemplateEntry {0}" + template.getQName());
}
xt.transform();
XdmNode ret = dest.getXdmNode();
if (ret != null && LOGR.isLoggable( FINE)) {
LOGR.log( FINE, "Output:\n" + ret.toString());
}
return ret;
}