Chapter 5. Using uml2svg

Table of Contents

Online Edition
Standalone Edition
Command prompt
Programming APIs

Online Edition

Using the online edition is as easy as one, two, three:

  1. Open your internet browser and go to

  2. Choose the XMI file you wish to convert

  3. Click the submit button and be prepared to wait

The time you will have to wait can vary greatly depending on the size of the file, the speed of your connection, the traffic load on the Internet and, most important, the load on our server. It can take anything between several seconds to a couple of minutes. As with all the free services on the web this is a best effort service, so the quality-of-service is not guaranteed. If you think that the transformation takes too much, you can use the Standalone Edition. You can even host your own transformation service on your own 1024-processor server and provide free access for everyone.

Standalone Edition


Before you can use the Standalone Edition of uml2svg you have downloaded from: you will have to extract the contents of the archive to a directory of your choice. You are done! The Online Edition needs no installation at all as it will run on the server.

Command prompt

Most XSLT processors allow you to perform a transformation by entering the right thing at the command prompt. “The right thing” is however dependent on which XSLT processor you are using. Suppose your diagram is in a file called Diagram.xmi located in the same directory you installed uml2svg, we give you the command to obtain the corresponding Image.svg.

Processor: xsltproc
Command: xsltproc --output Image.svg uml2svg.xsl Diagram.xmi
Processor: Apache Xalan-Java
Command: java org.apache.xalan.xslt.Process -IN Diagram.xmi -XSL uml2svg.xsl -OUT Image.svg
Processor: Saxon
Command: java net.sf.saxon.Transform -o Image.svg Diagram.xmi uml2svg.xsl

By default Saxon uses the XML parser that comes with Java but it can be set up to use a wide variety of XML parsers. All the relevant classes must be installed on your Java class path and the -x and -y options select the parser used for source files and the XSLT file respectively. Here is an example using Xerces:

java net.sf.saxon.Transform -o Image.svg -x org.apache.xerces.parsers.SAXParser -y org.apache.xerces.parsers.SAXParser Diagram.xmi uml2svg.xsl


Parameters may be used to customize the uml2svg transformation. They can be passed as command line arguments when invoking an XSLT processor. For example the parameter that selects the name of the diagram that is to be processed by uml2svg is SelectedDiagram. Suppose you want to extract the “ClassDiagram1” class diagram from Model.xmi. Depending on the XSLT processor, the transformation could be invoked like this:

xsltproc --output ClassDiagram1.svg --stringparam SelectedDiagram ClassDiagram1 uml2svg.xsl Model.xmi

java net.sf.saxon.Transform -o ClassDiagram1.svg Model.xmi uml2svg.xsl SelectedDiagram=ClassDiagram1

java org.apache.xalan.xslt.Process -IN Model.xmi -XSL uml2svg.xsl -OUT ClassDiagram1.svg -param SelectedDiagram ClassDiagram1

These commands will write only one diagram into the SVG file and not generate a navigation-tree, which will make it more easily usable for further editing and publishing.

Other two parameters SelectedDiagramNumber and SelectedDiagramId allow the selection of a diagram by its number or XMI identifier. The diagram number is given by the sequence of the diagrams in the file; the first position is 1. The XMI identifier of a diagram can be obtained from the is attribute of the desired UML:Diagram element. While these two methods seem more difficult to use than SelectedDiagram they are very helpful for automated processing.

Another useful parameter is UmlStdVersion that allows you to select the version of the the UML standard to use (i.e. 1.5 or 2.0).

Programming APIs

Additional to running XSL transformations on the command line, most XSLT processors offer an API which can be called from a programming language. No matter which programming language you are using there will probably be a way to do XST transformations. Other than the tools described in the section called “XSLT processors” you can also use:

Name: libxslt
Name: The XML::XSLT Perl module
Name: xslt module for PHP