The generated stylesheet can be integrated into testing like any other XSLT solution.
With a little meta work, the original Schematron schema can be integrated into the unit test.
public void testWithSchematron()
throws TransformerException, IOException {
StreamSource skeleton = new StreamSource(new File("skeleton1-5.xsl"));
StreamSource schema = new StreamSource(new File("plist.sct"));
StringWriter temp = new StringWriter();
StreamResult result = new StreamResult(temp);
// generate the stylesheet
TransformerFactory factory = TransformerFactory.newInstance();
Transformer xform = factory.newTransformer(skeleton);
xform.transform(schema, result);
temp.flush();
temp.close();
String stylesheet = temp.toString();
// now flip
StringReader in = new StringReader(stylesheet);
StreamSource sheet = new StreamSource(in);
Transformer validator = factory.newTransformer(sheet);
validator.setOutputProperty("method", "text");
temp = new StringWriter();
result = new StreamResult(temp);
validator.transform(new StreamSource(new File("thunderbirdplist.xml")), result);
temp.flush();
String output = temp.toString();
// Check for no output if all tests pass.
assertEquals(output, "", output);
// note use of output for both assertion message
// and test
}
Same issue as handcrafted XSLT-stylesheet-based tests: not good for unit tests;
Hard to find the place to set the breakpoint in the debugger and hard to step through since you end up deep in the XSLT code. After all the code is really XSLT, not Java. It's like trying to debug a Python program using an assembly level debugger.
The assertion is funny. We're basically checking that the stylesheet produces no output. This requires the text output method.