<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns="http://www.w3.org/1999/xhtml" 
	xmlns:msxsl="urn:schemas-microsoft-com:xslt"
	xmlns:Gen-it="http://mycompany.com/mynamespace"
	version="1.0">
<xsl:output method="html" encoding="us-ascii" indent="yes"/>

<xsl:variable name="ProjectName">SampleCase</xsl:variable>
<xsl:variable name="Author">&lt;Gen-it&gt;</xsl:variable>
<xsl:variable name="CreationDate">13-11-2000</xsl:variable>

<xsl:template match="/">
<html>
<head>
	<title>&lt;Gen-it&gt; HTML Documentation for <xsl:value-of select="$ProjectName"/></title>
</head>
<body>
<xsl:for-each select="//Class">
<b><xsl:value-of select="Gen-it:CapFirst(Class.name)"/></b><br/>
<xsl:value-of select="Class.documentation"/><br/><br/>
<b>Attributes:</b>
<table border="0" cellpaddin="2" width="800">
		<tr><td width="100"><b>name</b></td>
		<td width="100"><b>stereotype</b></td>
		<td width="100"><b>datatype</b></td>
		<td width="*"><b>documentation</b></td>
		</tr>
	<xsl:for-each select="Attribute">
		<tr><td><xsl:value-of select="Attribute.name"/></td>
		<td><xsl:value-of select="Attribute.stereotype"/></td>
		<td><xsl:value-of select="Attribute.datatype"/></td>
		<td><xsl:value-of select="Attribute.documentation"/></td>
	</tr>
		<xsl:for-each select="Reference">
		<tr><td></td><td>
			<xsl:if test="position()=1"><b>
				<xsl:if test="../Attribute.stereotype='PK'">Is referenced by:</xsl:if>
				<xsl:if test="../Attribute.stereotype='FK'">References:</xsl:if></b>
			</xsl:if>
			</td>
			<td colspan="2"><xsl:value-of select="Reference.class"/>.<xsl:value-of select="Reference.attribute"/><xsl:if test="Reference.aggregation!='none'"> (Collection)</xsl:if>
			</td>
		</tr>
		</xsl:for-each>
	</xsl:for-each>
</table><br></br>
</xsl:for-each>

</body>
</html>
</xsl:template>

<xsl:template match="Class" mode="primarykeyattribute">
	<xsl:for-each select="Attribute">
		<xsl:if test="Attribute.stereotype='PK'"><xsl:value-of select="Attribute.name"/></xsl:if>
	</xsl:for-each>
</xsl:template>

<xsl:template match="Attribute" mode="getdatatype">
	<!-- Datatype is defined by the datatype tag. -->
	<xsl:value-of select="Gen-it:FillSpace(Attribute.datatype, 20)"/>
</xsl:template>

<xsl:template match="Attribute" mode="NullOrNotNull">
	<!-- Datatype is defined by the stereotype tag. -->
	<!-- Except for attributes with a PK or FK stereotype. -->
	<xsl:if test="Attribute.stereotype='PK'">NOT NULL</xsl:if>
	<xsl:if test="Attribute.stereotype='FK'">
		<xsl:if test="Reference/Reference.optional='False'">NOT NULL</xsl:if>
		<xsl:if test="Reference/Reference.optional!='False'">NULL</xsl:if>
	</xsl:if>
	<xsl:if test="Gen-it:Lower(Attribute.stereotype)='not null'">NOT NULL</xsl:if>
	<xsl:if test="Gen-it:Lower(Attribute.stereotype)='null'">NULL</xsl:if>
	<xsl:if test="Gen-it:Lower(Attribute.stereotype)='optional'">NULL</xsl:if>
	<xsl:if test="Gen-it:Lower(Attribute.stereotype)='not optional'">NOT NULL</xsl:if>
</xsl:template>


<msxsl:script language="VBScript" implements-prefix="Gen-it">
	' <!-- Return the text of the node as all UPPERCASE -->
	Function Upper(nodelist) 
		Upper = UCASE(nodelist.nextNode().text)
	End Function
	' <!-- Return the text of the node as all lowercase -->
	Function Lower(nodelist) 
		Lower = LCASE(nodelist.nextNode().text)
	End Function
	' <!-- Return the text of the node with the first character converted to Uppercase -->
	Function CapFirst(nodelist) 
		dim strText
		dim strOutput
		strText = nodelist.nextNode().text
		strOutput = UCASE(Left( strText, 1))
		strOutput = strOutput + LCASE((Right( strText, LEN(strText)-1)))
		CapFirst = strOutput
	End Function
	' <!-- Return the text of the node plus spaces to create a string of the specified length -->
	Function FillSpace(nodelist, length) 
		dim strText
		dim strOutput
		strText = nodelist.nextNode().text
		strOutput = strText + String( length - LEN(strText) , " ")
		FillSpace = strOutput
	End Function
</msxsl:script>

</xsl:stylesheet>

