I use the classes that come with the JDK.
TransformerFactory tFactory = TransformerFactory.newInstance();
try {
tFactory.setAttribute("indent-number", "4");
} catch (IllegalArgumentException e) {
_log.warn("Unable to set indent-number on transfomer factory",
e);
}
StringWriter writer = new StringWriter();
Source source = new DOMSource(xsd.getAllSchemas()[0]);
Result result = new StreamResult(writer);
Transformer transformer;
String xsltFileName = getModel().getCustomXsltFileName();
if (xsltFileName == null || xsltFileName.trim().length() == 0) {
transformer = tFactory.newTransformer();
} else {
Source xsltSource = new StreamSource(new File(xsltFileName));
transformer = tFactory.newTransformer(xsltSource);
}
transformer.setOutputProperty(OutputKeys.ENCODING, getModel()
.getXsdEncoding());
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer
.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.STANDALONE, "no");
transformer.transform(source, result);
writer.flush();
As you can see, there is an attempt at setting indentation programmatically. Maybe that is interfering with your output directive?