<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:template match="/doc">
		
		<html>
			<head>
				<title>Vivio reference</title>
			</head>
			<style type="text/css">
				body {font-family: arial; background-color: #666699}
				h1 {font-size: 28pt;}
				h2 {font-size: 12pt;}
				h3 {font-size: 10pt;}
				.box {border-style: dotted; margin-left: 15; margin-right: 15; padding: 10px; background-color: #9999CC}
				.description{margin-left: 15; margin-right: 15; padding: 10px; font-size: 10pt; background-color: #CCCCFF}
			</style>
			<body>
				<h1>Vivio Reference</h1>
				
				<xsl:apply-templates/>
				
			</body>
		</html>
		
	</xsl:template>

	<xsl:template match="methods">
		
		<h2>
			Method group: <xsl:value-of select="@group"/>
		</h2>

		<div class="box">
			<xsl:apply-templates/>	
		</div>	
		
	</xsl:template>

	<xsl:template match="class">

		<h2>
			Class
			<xsl:value-of select="@name"/>
			<xsl:if test="@inherits">
				<i> inherits from </i>
				<xsl:value-of select="@inherits"/>
			</xsl:if>
		</h2>

		<div class="box">
			<xsl:apply-templates/>
		</div>

	</xsl:template>

	<xsl:template match="constructor">
		
		<h3>
			Constructor (
				<xsl:call-template name="param_list"/>
			)
		</h3>
		
	</xsl:template>
	
	<xsl:template match="method">

		<h3>

			<i>
				<xsl:choose>
					<xsl:when test="@return-type">
						<xsl:value-of select="@return-type"/>
						<xsl:text> </xsl:text>
					</xsl:when>
					<xsl:otherwise>
						void
					</xsl:otherwise>
				</xsl:choose>
			</i>
			
			<xsl:value-of select="@name"/>
			(
				<xsl:call-template name="param_list"/>
			)

		</h3>

		<xsl:apply-templates/>
		
	</xsl:template>

	<xsl:template match="description">
		<div class="description">
			<xsl:value-of select="text()"/>
		</div>
	</xsl:template>

	<xsl:template match="constant">
		<h3>
			Const
			<xsl:value-of select="@name"/>
			is
			<xsl:value-of select="@value"/>
			(
			<xsl:value-of select="@type"/>
			)
		</h3>
	</xsl:template>
	
	<xsl:template name="param_list">

		<xsl:for-each select="param">
		<i>
			<xsl:value-of select="@type"/>
			<xsl:if test="contains(@pass-by,'ref')">&amp;</xsl:if>
		</i>

			<xsl:text> </xsl:text>
			<xsl:value-of select="@name"/>
		
		<i>
			<xsl:if test="@default"> = <xsl:value-of select="@default"/></xsl:if>
		</i>

		<xsl:if test="position()!=last()">
			,
		</xsl:if>

		</xsl:for-each>

	</xsl:template>
	
</xsl:stylesheet>
