<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:dia="http://www.lysator.liu.se/~alla/dia/">
  <xsl:output method="text" indent="no" />

  <xsl:template match="dia:object">
    <xsl:if test="starts-with(@type,'UML - Class')">
    <!-- create table -->
      <xsl:text>CREATE TABLE </xsl:text>
      <xsl:apply-templates />
    <!-- end of create -->
      <xsl:text>
);

</xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template match="dia:attribute">
    <xsl:if test="starts-with(@name,'name')">
      <!-- process the name node -->
      <xsl:call-template name="astring" />
      <xsl:text> (
</xsl:text>
      <xsl:apply-templates />
    </xsl:if>
    <xsl:if test="starts-with(@name,'attributes')">
      <!-- process the attributes as each element in the table -->
      <xsl:for-each select="dia:composite">
        <xsl:text> </xsl:text><xsl:value-of select="substring-before(substring-after(dia:attribute[@name='name']/dia:string,'#'),'#')" />
        <xsl:text> </xsl:text>
        <xsl:value-of select="substring-before(substring-after(dia:attribute[@name='type']/dia:string,'#'),'#')" />
        <xsl:text> </xsl:text>
        <xsl:value-of select="substring-before(substring-after(dia:attribute[@name='value']/dia:string,'#'),'#')" />
        <xsl:if test="not(position()=last())">
          <xsl:text>,
</xsl:text>
        </xsl:if>
      </xsl:for-each>
    </xsl:if>
  </xsl:template>

  <xsl:template name="astring">
    <xsl:value-of select="substring-before(substring-after(dia:string,'#'),'#')" />
  </xsl:template>

  <xsl:template match="dia:string" />

  <xsl:template match="text()" />

</xsl:stylesheet>
