use of net.sf.saxon.s9api.XsltCompiler in project sirix by sirixdb.
the class TestNodeWrapperS9ApiXSLT method saxonTransform.
/**
* Transform source document with the given stylesheet.
*
* @param xml
* Source xml file.
* @param stylesheet
* Stylesheet to transform sourc xml file.
* @throws SaxonApiException
* Exception from Saxon in case anything goes wrong.
*/
@Ignore("Not a test, utility method only")
public void saxonTransform(final File xml, final File stylesheet) throws SaxonApiException {
final Processor proc = new Processor(false);
final XsltCompiler comp = proc.newXsltCompiler();
final XsltExecutable exp = comp.compile(new StreamSource(stylesheet));
final XdmNode source = proc.newDocumentBuilder().build(new StreamSource(xml));
final Serializer out = new Serializer();
out.setOutputProperty(Serializer.Property.METHOD, "xml");
out.setOutputProperty(Serializer.Property.INDENT, "yes");
out.setOutputFile(new File(TestHelper.PATHS.PATH1.getFile(), "books1.html"));
final XsltTransformer trans = exp.load();
trans.setInitialContextNode(source);
trans.setDestination(out);
trans.transform();
}
use of net.sf.saxon.s9api.XsltCompiler in project sirix by sirixdb.
the class TestXSLTTransformation method testTransform.
@Test
public void testTransform() throws Exception {
final Processor proc = new Processor(false);
final XsltCompiler compiler = proc.newXsltCompiler();
try {
final XsltExecutable exec = compiler.compile(new StreamSource(new File(STYLESHEET)));
final XsltTransformer transform = exec.load();
transform.setSource(new StreamSource(new FileInputStream(INPUT)));
final Serializer serializer = new Serializer();
final OutputStream out = new ByteArrayOutputStream();
serializer.setOutputStream(out);
transform.setDestination(serializer);
transform.transform();
final StringBuilder expected = TestHelper.readFile(new File(EXPECTED), false);
assertEquals("XML files match", expected.toString(), new StringBuilder("<root>").append(out.toString()).append("</root>").toString());
} catch (final SaxonApiException e) {
LOGWRAPPER.error(e);
}
}
use of net.sf.saxon.s9api.XsltCompiler in project sirix by sirixdb.
the class XSLTEvaluator method call.
@Override
public OutputStream call() {
final Processor proc = new Processor(false);
final XsltCompiler comp = proc.newXsltCompiler();
XsltExecutable exp;
XdmNode source;
try {
final Configuration config = proc.getUnderlyingConfiguration();
final NodeInfo doc = new DocumentWrapper(mSession, config);
exp = comp.compile(new StreamSource(mStylesheet));
source = proc.newDocumentBuilder().build(doc);
if (mSerializer == null) {
final Serializer out = new Serializer();
out.setOutputProperty(Serializer.Property.METHOD, "xml");
out.setOutputProperty(Serializer.Property.INDENT, "yes");
out.setOutputStream(mOut);
mSerializer = out;
} else {
mSerializer.setOutputStream(mOut);
}
final XsltTransformer trans = exp.load();
trans.setInitialContextNode(source);
trans.setDestination(mSerializer);
trans.transform();
} catch (final SaxonApiException e) {
LOGGER.error("Saxon exception: " + e.getMessage(), e);
} catch (final SirixException e) {
LOGGER.error("TT exception: " + e.getMessage(), e);
}
return mOut;
}
use of net.sf.saxon.s9api.XsltCompiler in project sirix by sirixdb.
the class XMLReduce method reduce.
@Override
public void reduce(final DateWritable paramKey, final Iterable<Text> paramValue, final Context paramContext) throws IOException, InterruptedException {
final StringBuilder builder = new StringBuilder("<root>");
for (final Text event : paramValue) {
System.out.println(event.toString());
builder.append(event.toString());
}
builder.append("</root>");
// System.out.println(builder.toString());
final Processor proc = new Processor(false);
final XsltCompiler compiler = proc.newXsltCompiler();
try {
final XsltExecutable exec = compiler.compile(new StreamSource(new File(STYLESHEET)));
final XsltTransformer transform = exec.load();
transform.setSource(new StreamSource(new StringReader(builder.toString())));
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final Serializer serializer = new Serializer();
serializer.setOutputStream(out);
transform.setDestination(serializer);
transform.transform();
final String value = out.toString();
// System.out.println(value);
paramContext.write(null, new Text(value));
} catch (final SaxonApiException e) {
LOGWRAPPER.error(e);
}
}
Aggregations