private boolean transform() {
try {
//configure parser
SAXParser parser = new SAXParser();
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", xsdSource);
parser.setErrorHandler(new DefaultHandler());
//parse source file to validate it
if (validate) {
parser.parse(new InputSource(new BufferedInputStream(new FileInputStream(xmlSource))));
}
//transform
dSource = new StreamSource(xmlSource);
dResult = new StreamResult(xmlDestination);
transf = TransformerFactory.newInstance().newTransformer(new StreamSource(xsltTransformer));
transf.transform(dSource, dResult);
//configure parser
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", xsdDestination);
parser.setErrorHandler(new DefaultHandler());
//parse destination file to validate it
if (validate) {
parser.parse(new InputSource(new BufferedInputStream(new FileInputStream(xmlDestination))));
}
//transformation successful
return true;