Expressed in XMI, a model can be interchanged between tools that are aware of model elements. However, this format is not very consumable for the human reader neither is it well suited for tools that are purely graphically oriented. Therefore a transformation into a graphical format is needed. The format most promising for this purpose is SVG. The format proposed in this specification is well prepared for a transformation into SVG and was explicitly designed to make this transformation as straightforward as possible. Both data formats, XMI and SVG, are applications of XML and the common set of XML tools can be used to manipulate them. XSLT is such a mechanism that is designed to transform one XML format into another. For proof of concept, this proposal includes a set of XSLT scripts to transform a model given in XMI[UML+DI] into SVG. At the current stage this is applied to information regarding class diagrams only.
As set out in the following paragraphs, these stylesheets extract information from an XMI file with model and DI data and build a new SVG document out of this. The resulting SVG file contains the representation of a single class diagram in UML notation.
The next section describes the transformation concept for class diagrams. This is followed by a section containing the discussion about further extensions of the stylesheets. This includes, for instance, a suggestion how to deal with DI files which store several diagrams and a discussion about transformation of other diagram types. The stylesheets are designed to generate different notations with small modifications. More about this issue can be found in the last section.
A transformation using XSLT scripts is based on a set of templates. In our implementation we need one template which matches the first class diagram in a diagram interchange file. All other information such as model data is used later on to obtain single values such as class or attribute names (script: xmi2svg.xsl).
Once a class diagram is matched, a named template is implemented to generate the SVG header on some standard elements which can be reused for the diagram elements to be created later on (script: build_diagramm.xsl).
With the usage of <apply-templates> the XSLT processor will iterate over all child elements of the diagram. These children can be node elements such as a class or an association-end or edge elements such as associations or generalizations. Templates which match these elements can be found in build_nodeelem.xsl and build_edgeelem.xsl.
The templates of build_nodeelem.xsl and build_edgeelem.xsl need to know about the kind of model element which is associated with the node or edge element matched. To obtain this information, we need to follow the link attribute. This is done by means of a couple of named templates in util_modellookup.xsl.
The model element type (e.g. class or generalization) is used as condition for calling other named templates for generating SVG elements. These named templates can be found in build_class.xsl, build_assozend.xsl, and build_edge.xsl. Each of them uses util_modellookup to get the text elements, e.g., class or operation name, which are to be represented.
Another kind of information which needs to be extracted is the model information on the association ends if an edge is represented in the diagram. In this case the scripts call a lookup routine for each of the edge ends and generate an SVG element based on the attributes returned. For instance, a navigable flag might be set for an edge end. This will lead to a generation of an solid arrow if the other edge end does not have a navigation flag set.
The representation of an edge is very simple when using the <path> element of SVG. The coordinates of the points of an edge need to be written into an attribute of the path element. To do so, we created a template which matches all points and generates a string (util_createpath.xsl).
As set out in the paragraphs above, all information for generating the SVG can be taken from diagram interchange or model interchange data. The linkage of corresponding elements makes it easy to write XSLT scripts for a general transformation to SVG.