try {
XdmNode doc = source.read();
String text = doc.getStringValue();
SourceStringReader reader = new SourceStringReader(text);
FileFormat fmt = "svg".equals(format) ? FileFormat.SVG : FileFormat.PNG;
String desc = reader.generateImage(baos, new FileFormatOption(fmt));
if (desc == null) {
throw new XProcException("PlantUML diagram returned null");
}