The following patch allows applying custom xsl
transformation (including parameters to transformer,
such as doctype or character encoding) to GXL document
while saving it.
The package includes modified
net/sourceforge/gxl/GxlDocument file, a separated
xmlPrettyprinter.xsl (previously in GxlDocument) and
the following usage examples:
GXLDocument gxlDocument = new GXLDocument();
// ...
// default transform with modified encoding
Transformer t = gxlDocument.getDefaultTransfomer();
t.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
gxlDocument.write(new File("MyFirstGXL.xml"),t);
// plain transform (we need to explicitly set doctype
to make it vali)
TransformerFactory tf = TransformerFactory.newInstance();
t = tf.newTransformer();
t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"http://www.gupro.de/GXL/gxl-1.0.dtd");
gxlDocument.write(new File("MySecondGXL.xml"),t);
// same as above, but declare as gxl 1.1 output
t = tf.newTransformer();
t.setOutputProperty(OutputKeys.INDENT,"yes");
t.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"http://www.gupro.de/GXL/gxl-1.1.dtd");
gxlDocument.write(new File("My3rdGXL.xml"),t);
// and finally, a custom transform that outputs the
graph as a basic html
t = tf.newTransformer(new StreamSource(new
File("CustomTransformer.xsl")));
gxlDocument.write(new File("TransformerGXL.html"),t);
Source code for the patch