Reverse engineer DataBase (episode 2) Generating Class Diagram Image from XMI.

in my last article (Reverse engineer DataBase to XMI.)

I wrote how to reverse  engineer DataBase and produce XMI file from the data base using andromda Schema2xmi plug-in.

in this article I will speak about how to produce PNG (Portable Network Graphics) Image or any other type of Image that produces the Class Diagram representation from the XMI file that we produced earlier from our Data Base.

ok lets start.

I will use XSLT, and graphviz to achieve this task.


   1. XSLT 2.0.

   2. graphviz.

Requiered steps to generate the png class diagram from our xmi file are:

  1. Write XSL file that generate the dot file from our xmi.
  2. Generate the dot file using the XSL file.
  3. Use graphviz to generate the png image from the dot file.

1. Writing the XSL transformer file that generate the dot file from our xmi:

the following is the XSL file (XMITransformer.xsl) that applies to our xmi file and produces the dot file from it.


<xsl:stylesheet version="2.0"      
                exclude-result-prefixes="xs xdt UML">

    <!--xsl:key name="class" match="UML:Class" use="" /-->
    <xsl:output method="text" media-type="text/xml" indent="yes" encoding="ISO-8859-1" />
    <xsl:variable name="from" select="0"/>
    <xsl:variable name="to" select="NON"/>
    <xsl:template match="XMI.header"/>
    <xsl:template match="XMI.content">
        <xsl:call-template name="pre-graph"/>
                    select="UML:Model/UML:Namespace.ownedElement/UML:Package/UML:Namespace.ownedElement/UML:Class" />     
        <xsl:call-template name="post-graph"/>
        <!--xsl:call-template name="attributes"/>
        <xsl:call-template name="functions"/-->
    <xsl:template name="attributes">
        int x;
    <xsl:template name="functions">
        public static void main(String[] args){
    <xsl:template name="pre-graph">
        digraph g {      
        graph [      
        rankdir = "LR"      

        node [      
        fontsize = "16"      
        shape = "ellipse"
        edge [
    <xsl:template name="post-graph">
    <xsl:template match="UML:Namespace.ownedElement/UML:Class">
        <!--"<xsl:value-of select=""/>" [
        label = "<xsl:value-of select="@name"/>"
        shape = "record"
        "<xsl:value-of select=""/>" [
        label = "<xsl:value-of select="@name"/> | <xsl:value-of select="@visibility"/> |  "
        shape = "record"
        <!--xsl:text>  </xsl:text>
        <xsl:value-of select="@visibility"/-->
        <!-- new Line character-->
        <!--xsl:text>&#xa;        </xsl:text-->
    <xsl:template match="UML:Association.connection">
        <xsl:apply-templates select="UML:AssociationEnd/UML:AssociationEnd.participant/UML:Class"/>

    <xsl:template match="UML:Association">
        <xsl:variable name="f"
        "<xsl:value-of select="$f[1]"/>" -> "<xsl:value-of select="$f[2]"/>" [
        id = <xsl:value-of select=""/>

    <xsl:template match="UML:Attribute">


2. Generate the dot file using the XSL file:

 java net.sf.saxon.Transform -o transformed.xmi XMITransformer.xsl

3. Use graphviz to generate the png image from the dot file:

dot -Tpng -o Diagram.png

It is imperative that we

It is imperative that we read blog post very carefully. I am already done it and find that this post is really amazing.
Language of Desire

Most of the time I

Most of the time I
don’t make comments on websites, but I'd like to say that this article really
forced me to do so. Really nice post!
Check this out