uml2xhtml.xsl
Author
Zhou Renjian
Create@
2004-11-29 05:44
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xhtml" version="1.0" indent="yes" undeclare-namespaces="yes"/>
<xsl:variable name="gIconsLocation" select="'file:///W:/uml/icons/obj16'"/>
<xsl:template match="/uml">
<xsl:call-template name="xhtml-doctype-header"/>
<html>
<head>
<title>
<xsl:value-of select="@title"/>
</title>
</head>
<body style="background-color:#fffdf2;">
<xsl:for-each select="classwrapper">
<xsl:call-template name="uml-class-xyw">
<xsl:with-param name="class" select="class"/>
<xsl:with-param name="position-type" select="@position-type"/>
<xsl:with-param name="x" select="@left"/>
<xsl:with-param name="y" select="@top"/>
<xsl:with-param name="w" select="@width"/>
</xsl:call-template>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template name="uml-class-xyw">
<xsl:param name="class"/>
<xsl:param name="position-type"/>
<xsl:param name="x"/>
<xsl:param name="y"/>
<xsl:param name="w"/><!-- width -->
<div style="position:{$position-type};left:{$x}px;top:{$y}px;width:{$w}px;">
<xsl:call-template name="uml-class-width">
<xsl:with-param name="class" select="$class"/>
<xsl:with-param name="width" select="'100%'"/>
</xsl:call-template>
</div>
</xsl:template>
<xsl:template name="uml-class-width">
<xsl:param name="class"/>
<xsl:param name="width"/>
<xsl:param name="is-inner"/>
<xsl:variable name="class-title-css">
<xsl:choose>
<xsl:when test="boolean($is-inner)">padding:2px;padding-left:4px;padding-right:4px;height:24px;</xsl:when>
<xsl:otherwise>padding:4px;padding-left:4px;padding-right:4px;height:35px;</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="class-title-font-css">
<xsl:choose>
<xsl:when test="boolean($is-inner)">font-size:10pt;font-weight:bold;</xsl:when>
<xsl:otherwise>font-size:11pt;</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="class-title-image-css">
<xsl:choose>
<xsl:when test="boolean($is-inner)">margin-top:2px;</xsl:when>
<xsl:otherwise>margin-top:3px;</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<table cellpadding="0" cellspacing="0" border="0" style="margin-bottom:2px;background-color:white;border-right:2px solid #bbbbbb;border-bottom:2px solid #bbbbbb;font-family:Arial, sans-serif;font-size:10pt;width:{$width};">
<tr valign="middle">
<td align="center" style="border:solid 1px black;{$class-title-css}">
<table cellpadding="0" cellspacing="0" border="0" style="{$class-title-font-css}">
<tr valign="middle">
<td>
<div style="height:20px;overflow:hidden;">
<xsl:element name="img">
<xsl:attribute name="style"><xsl:value-of select="$class-title-image-css"/></xsl:attribute>
<xsl:attribute name="src">
<xsl:value-of select="concat($gIconsLocation, '/')"/>
<xsl:choose>
<xsl:when test="boolean($is-inner)">
<xsl:value-of select="'innerclass_'"/>
<xsl:choose>
<xsl:when test="$class/@decorator = 'public'">public</xsl:when>
<xsl:when test="$class/@decorator = 'protected'">protected</xsl:when>
<xsl:when test="$class/@decorator = 'private'">private</xsl:when>
<xsl:otherwise>default</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$class/@decorator = 'public'">class</xsl:when>
<xsl:when test="$class/@decorator = 'protected'">class_default</xsl:when>
<xsl:otherwise>class_default</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="'_obj.gif'"/>
</xsl:attribute>
<xsl:attribute name="width" select="16"/>
<xsl:attribute name="height" select="16"/>
<xsl:attribute name="alt">
<xsl:if test="boolean($is-inner)">
<xsl:value-of select="'inner '"/>
</xsl:if>
<xsl:if test="boolean($class/@decorator)">
<xsl:value-of select="concat($class/@decorator, ' ')"/>
</xsl:if>
<xsl:value-of select="name($class)"/>
</xsl:attribute>
</xsl:element>
</div>
</td>
<td>
<span><xsl:value-of select="$class/@name"/></span>
</td>
</tr>
</table>
</td>
</tr>
<xsl:if test="count($class/attribute) > 0">
<tr>
<td style="border:solid 1px black;border-top-style:none;padding:4px;padding-left:4px;padding-right:4px;">
<xsl:call-template name="uml-item-list">
<xsl:with-param name="list" select="$class/attribute"/>
</xsl:call-template>
</td>
</tr>
</xsl:if>
<xsl:if test="count($class/method) > 0">
<tr>
<td style="border:solid 1px black;border-top-style:none;padding:4px;padding-left:4px;padding-right:4px;">
<xsl:call-template name="uml-item-list">
<xsl:with-param name="list" select="$class/method"/>
</xsl:call-template>
</td>
</tr>
</xsl:if>
<xsl:if test="count($class/class) > 0">
<tr>
<td style="border:solid 1px black;border-top-style:none;padding:4px;padding-left:4px;padding-right:4px;">
<xsl:for-each select="$class/class">
<xsl:call-template name="uml-class-width">
<xsl:with-param name="class" select="."/>
<xsl:with-param name="width" select="'100%'"/>
<xsl:with-param name="is-inner" select="'true'"/>
</xsl:call-template>
</xsl:for-each>
</td>
</tr>
</xsl:if>
</table>
</xsl:template>
<xsl:template name="uml-item-list">
<xsl:param name="list"/>
<table cellpadding="0" cellspacing="0" border="0">
<xsl:for-each select="$list">
<tr valign="middle">
<td style="height:23px;">
<xsl:call-template name="uml-item">
<xsl:with-param name="type" select="name(.)"/>
<xsl:with-param name="decorator" select="@decorator"/>
<xsl:with-param name="label" select="."/>
</xsl:call-template>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template name="uml-item">
<xsl:param name="type"/>
<xsl:param name="decorator"/>
<xsl:param name="label"/>
<table cellpadding="0" cellspacing="0" border="0" style="font-size:10pt;">
<tr valign="top">
<td>
<xsl:element name="img">
<xsl:attribute name="style">margin-top:2px;</xsl:attribute>
<xsl:attribute name="src">
<xsl:value-of select="concat($gIconsLocation, '/')"/>
<xsl:choose>
<xsl:when test="$type = 'method'">
<xsl:value-of select="'meth'"/>
<xsl:choose>
<xsl:when test="$decorator = 'public'">pub</xsl:when>
<xsl:when test="$decorator = 'protected'">pro</xsl:when>
<xsl:when test="$decorator = 'private'">pri</xsl:when>
<xsl:otherwise>def</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$type = 'attribute'">
<xsl:value-of select="'field_'"/>
<xsl:choose>
<xsl:when test="$decorator = 'public'">public</xsl:when>
<xsl:when test="$decorator = 'protected'">protected</xsl:when>
<xsl:when test="$decorator = 'private'">private</xsl:when>
<xsl:otherwise>default</xsl:otherwise>
</xsl:choose>
</xsl:when>
</xsl:choose>
<xsl:value-of select="'_obj.gif'"/>
</xsl:attribute>
<xsl:attribute name="width" select="16"/>
<xsl:attribute name="height" select="16"/>
<xsl:attribute name="alt">
<xsl:if test="boolean($decorator)">
<xsl:value-of select="concat($decorator, ' ')"/>
</xsl:if>
<xsl:value-of select="$type"/>
</xsl:attribute>
</xsl:element>
</td>
<td>
<xsl:value-of select="$label"/>
</td>
</tr>
</table>
</xsl:template>
<xsl:template name="xhtml-doctype-header">
<xsl:value-of disable-output-escaping="yes">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
</xsl:value-of>
<xsl:value-of disable-output-escaping="yes"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
</xsl:value-of>
</xsl:template>
</xsl:stylesheet>