<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!-- HTML Entity references: -->
	<!ENTITY copy "&#169;">
	<!ENTITY nbsp "&#160;">
]>
<!--
	===========================================================================
	HTML rendering of Gomorphv2 specification file 
	===========================================================================
	
	Created in 2003.
	
	Revision history:
	[2004-06-05]
	[2026-01-27] XSLT 3.0, HTML5, improved markup (dl → ol e.a.), edited CSS
	[2026-05-31] stylesheet no longer expects default DTD attributes; added tagset description 
	
	Tom De Herdt
	https://www.wulfila.be/
	
	===========================================================================
-->
<xsl:stylesheet 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	version="3.0">
	
	<xsl:strip-space elements="*"/>
	
	<xsl:output
		method="html"
		html-version="5.0"
		include-content-type="no"
		indent="yes"
	/>
	
	<xsl:variable name="undefined">
		<span class="undefined">undefined</span>
	</xsl:variable>
	
	<xsl:variable name="toplink">
		<p class="toplink"><a href="#TOC" title="Table of contents">TOC</a></p>
	</xsl:variable>
	
	<xsl:variable name="style" xml:space="preserve"><style>
body {
    margin: 2%;
    font-family: "Open Sans", sans-serif;
    font-size: 11pt;
    min-width: 20em;
    max-width: 75em;
}

a:link, a:visited {
    color: blue;
    text-decoration: none;
}
a:hover {
    color: navy;
    text-decoration: underline;
}
a:active {
    color:coral;
}

div.info {
    margin: 2%;
    line-height: 140%;
}

p.summary {
    font-style: italic;
}

footer {
    border-top: 1px solid;
    margin-top: 3em;
    padding: 0.5em 0.5em;
}

h1 {
    font-size: 16pt;
    font-weight: normal;
}

h2 {
    font-size: 14pt;
    font-weight: normal;
    padding-left: 0.2em;
    padding-bottom: 0.2em;
    border-bottom: 1px solid;
    margin-top: 2em;
}

h3 {
    font-size: 12pt;
    font-weight: bold;
}

p.toplink {
    text-align: right;
    font-size: 10pt;
    margin-top: 0.2em;
    margin-bottom: 0.2em;
}

p.description {
    border-style: solid;
    border-width: 1px;
    padding: 0.7em;
    line-height: 1.3em;
    margin-bottom: 0;
}

ul {
    margin-top: 0;
    margin-bottom: 0;
}

ul.statements {
    background-color: #EEEEEE;
    padding: 0.7em;
    margin-top: 0.6em;
    line-height: 1.3em;
    list-style-type: none;
}

ul.statements li ol,
ul.statements li ul {
    list-style: none;
}

ul.statements li ol,
ul.statements li ul,
ul.statements li p {
    padding-left: 40px;
    padding-inline-start: 40px;
}

ul.statements li ol {
    counter-reset: steps;
}
ul.statements li p {
    margin: 0;
}

ul.statements li ol li:before {
    content: "(" counter(steps) ") ";
    color: gray;
}

ul.statements li ol li {
    counter-increment: steps;
}

var {
    font-weight: bold;
    font-style: normal;
}

var.variable {
    color: #000080;
}

var.parameter {
    color: #000080;
}

var.function {
    color: maroon;
}

var.entity {
    font-style: normal;
    font-weight: normal;
}

code, span.regex, span.tag, dfn.entity {
	font-family: Consolas, monospace;
}

code.regex {
    font-style: normal;
    font-weight: normal;
    color: #005A9C; /* W3C blue */
}

table.entities td,
table.entities th {
    padding-left: 1em;
    padding-right: 1em;
}

th {
    text-align: left;
}

dfn {
    font-style: normal;
}

span.lit {
    color: teal;
}

span.array {
    color: teal;
}

span.range {
    color: navy;
}

span.emph-operator {
    color: red;
    font-weight: bold;
}

span.expression {
    color: navy;
}

span.regex {
    color: navy;
}

span.null {
    color: red;
}

span.classnumber {
    color: gray;
}

.undefined {
    color: red;
}

span.TOCLevel1 {
    background-color: #EEEEEE;
    padding: 0.2em;
}

@media print {
    body {
        font-size: 10pt;
    }

    p.toplink {
        display: none;
    }
}</style>
	</xsl:variable>
	
	<xsl:template match="gomorph">
		<html lang="en">
			<head>
				<meta charset="utf-8" />
				<meta name="viewport" content="width=device-width, initial-scale=1.0" />
				<title>Gomorphv2: <xsl:value-of select="documentation/language/name"/> morphology</title>
				<!--<link rel="stylesheet" href="gomorph.css"/>-->
				<xsl:sequence select="$style"/>
			</head>
			<body>	
				<h1>Gomorphv2: <strong><xsl:value-of select="documentation/language/name"/></strong> inflectional morphology</h1>
				
				<div id="documentation">
					<h2>Header</h2>
					<xsl:apply-templates select="documentation"/>
				</div>
				
				<div id="TOC">
					<h2>Table of contents</h2>
					<div class="info">
						<xsl:for-each select="//class[not(@inherits)]">
							<br/>
							<span class="TOCLevel1">
								<strong><xsl:value-of select="position()"/>&#xA0;</strong>
								<a href="#C_{@name}">
									<xsl:apply-templates select="@description" mode="title"/>
									<xsl:text>Base class </xsl:text>
									<xsl:value-of select="@name"/>
								</a>
							</span>
							<br/>
							<xsl:call-template name="ProcessDerivedClasses">
								<xsl:with-param name="ParentClass">
									<xsl:value-of select="@name"/>
								</xsl:with-param>
								<xsl:with-param name="Ref">
									<xsl:value-of select="position()"/>
								</xsl:with-param>
							</xsl:call-template>
						</xsl:for-each>
					</div>
				</div>
				
				<div id="tagsets">
					<h2>Tagsets</h2>
					<xsl:apply-templates select="morphology/tagsets"/>
					<xsl:sequence select="$toplink"/>
				</div>
				
				<div>
					<h2>Regular expressions</h2>
					<p>Syntax: <xsl:value-of select="morphology/rgx-definition/syntax/@name"/> [<a href="{morphology/rgx-definition/syntax/@definitionURI}"><xsl:value-of select="morphology/rgx-definition/syntax/@definitionURI"/></a>]</p>
					<p>Entities:</p>
					<xsl:apply-templates select="morphology/rgx-definition"/>
					<xsl:sequence select="$toplink"/>
				</div>
				
				<div>
					<h2>Morphological classes</h2>
					<xsl:apply-templates select="morphology/classes"/>
				</div>
				
				<footer>
					<xsl:text>&copy;&nbsp;</xsl:text>
					<xsl:value-of select="documentation/credits/copyright"/>
				</footer>
			</body>
		</html>
	</xsl:template>
	
	<xsl:template match="@description" mode="title">
		<xsl:attribute name="title" select="."/>
	</xsl:template>
	
	<xsl:template name="ProcessDerivedClasses">
		<xsl:param name="ParentClass"/>
		<xsl:param name="Ref"/>
		<xsl:variable name="Children" select="../class[@inherits=$ParentClass]"/>
		<xsl:choose>
			<xsl:when test="$Children">
				<xsl:for-each select="$Children">
					<xsl:value-of select="concat('·&#xA0;&#xA0;&#xA0;', $Ref, '.', position())"/>
					<xsl:text>&#xA0;</xsl:text>
					<a href="#C_{@name}">
						<xsl:apply-templates select="@description" mode="title"/>
						<xsl:text>Derived </xsl:text>
						<xsl:if test="@abstract='true'">abstract</xsl:if>
						<xsl:text> class </xsl:text>
						<xsl:value-of select="@name"/>
					</a>
					<br/>
					<xsl:call-template name="ProcessDerivedClasses">
						<xsl:with-param name="ParentClass">
							<xsl:value-of select="@name"/>
						</xsl:with-param>
						<xsl:with-param name="Ref">
							<xsl:value-of select="concat('·&#xA0;&#xA0;&#xA0;', $Ref, '.', position())"/>
						</xsl:with-param>
					</xsl:call-template>
				</xsl:for-each>
			</xsl:when>
			<xsl:otherwise></xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="entities">
		<table class="entities">
			<tr>
				<th>Symbol</th>
				<th>Expression</th>
				<th>Description</th>
			</tr>
			<xsl:apply-templates/>
		</table>
	</xsl:template>
	
	<xsl:template match="symbol">
		<tr>
			<td><dfn class="entity">{<xsl:value-of select="@name"/>}</dfn></td>
			<td><code class="regex">/<xsl:value-of select="@value"/>/</code></td>
			<td><xsl:value-of select="@description"/></td>
		</tr>
	</xsl:template>
	
	<xsl:template match="documentation">
		<xsl:variable name="url" select="credits/link/@uri"/>
		<div class="info">
			<p>
				<xsl:text>Language: </xsl:text>
				<strong><xsl:value-of select="language/name"/></strong>
				<xsl:if test="language/@ISO639">
					<xsl:text> [ISO 639 code: </xsl:text>
					<strong><xsl:value-of select="language/@ISO639"/></strong>
					<xsl:text>]</xsl:text>  
				</xsl:if> 
				<xsl:if test="language/@SILCode">
					<xsl:text> [</xsl:text>
					<abbr title="SIL International (formerly known as the Summer Institute of Linguistics)">SIL</abbr>
					<xsl:text> code: </xsl:text>
					<strong><xsl:value-of select="language/@SILCode"/></strong>
					<xsl:text>]</xsl:text>
				</xsl:if>
			</p>
			<p class="summary"><xsl:value-of select="language/description"/></p>
			<p>
				<xsl:text>Filename: </xsl:text><a href="../{document/filename}"><xsl:value-of select="document/filename"/></a><br/>
				<xsl:text>Version: </xsl:text><xsl:value-of select="document/version"/> (last modified on <xsl:value-of select="document/revision-history/@last-modified"/>)<br/>
				<xsl:text>History:</xsl:text><br/>
				<xsl:for-each select="document/revision-history/revision">
					<xsl:text>&#x00A0;&#x00A0;&#x00A0;&#x00A0;</xsl:text>
					<xsl:value-of select="@version"/> [<xsl:value-of select="@date"/>]: <xsl:value-of select="."/><br/>
				</xsl:for-each>
			</p>
			<p>
				<xsl:text>Author: </xsl:text><xsl:value-of select="credits/author"/><br/>
				<xsl:text>URL: </xsl:text><a href="{$url}"><xsl:value-of select="$url"/></a>
			</p>
			<p>This HTML document was generated from the source file <a href="../../format/Gomorphv2.xsl">with XSLT</a> on <xsl:value-of select="current-dateTime()"/>.</p>
		</div>
	</xsl:template>
	
	<xsl:template match="tagsets">
		<xsl:apply-templates/>
	</xsl:template>

	<xsl:template match="tagset">
		<h3><xsl:number/>. <xsl:value-of select="@name"/></h3>
		<xsl:apply-templates select="@description"/>
		<div id="TS_{@name}">
			<ol>
				<xsl:apply-templates select="tag"/>
			</ol>
		</div>
	</xsl:template>
	
	<xsl:template match="tagset/@description">
		<p><xsl:value-of select="."/></p>
	</xsl:template>
	
	<xsl:template match="tag">
		<li>
			<span class="tag"><xsl:value-of select="@name"/></span>
			<xsl:text>: </xsl:text>
			<xsl:value-of select="@description"/>
		</li>
	</xsl:template>
		
	<xsl:template match="classes">
		<xsl:apply-templates/>
	</xsl:template>
	
	<xsl:template match="class">
		<div id="C_{@name}" class="class">
			<h3>
				<span class="classnumber">(<xsl:number/>)</span>
				<xsl:choose>
					<xsl:when test="(@abstract='true') and @inherits"> Abstract derived class </xsl:when>
					<xsl:when test="(@abstract='true') and not(@inherits)"> Abstract base class </xsl:when>
					<xsl:when test="not(@abstract='true') and @inherits"> Derived class </xsl:when>
					<xsl:when test="not(@abstract='true') and not(@inherits)"> Base class </xsl:when>
					<xsl:otherwise> Class </xsl:otherwise>
				</xsl:choose>
				<span class="classname"> "<xsl:value-of select="@name"/>" </span>
				<xsl:if test="@inherits"> [inherits <a href="#C_{@inherits}"><xsl:value-of select="@inherits"/></a>]</xsl:if>
				<xsl:if test="@tagset"> [tagset <a href="#TS_{@tagset}"><xsl:value-of select="@tagset"/></a>]</xsl:if>
			</h3>
			<xsl:apply-templates select="@description"/>
			<xsl:apply-templates select="parameters"/>
			<xsl:apply-templates select="functions"/>
			<xsl:apply-templates select="paradigm"/>
			<xsl:apply-templates select="conditions"/>
			<xsl:sequence select="$toplink"/>
		</div>
	</xsl:template>
	
	<xsl:template match="class/@description">
		<p class="description"><strong>Description:</strong><xsl:text> </xsl:text><xsl:value-of select="."/></p>
	</xsl:template>
	
	<xsl:template match="parameters[parameter]|functions[function]|paradigm[variable]|conditions[when]">
		<ul class="statements">
			<xsl:apply-templates/>
		</ul>
	</xsl:template>
	
	<xsl:template match="parameter">
		<li>
			<xsl:text>Parameter </xsl:text>
			<var class="parameter"><xsl:value-of select="@name"/></var>
			<xsl:if test="@pattern">
				<xsl:text> [pattern: /</xsl:text>
				<xsl:value-of select="@pattern"/>
				<xsl:text>/ </xsl:text>
				<xsl:if test="@case-sensitive='true'">(case-sensitive)</xsl:if>
				<xsl:text>] </xsl:text>
			</xsl:if>
			<xsl:if test="@default">
				<xsl:text> [default value</xsl:text>
				<xsl:if test="@default-type='expression'">(s)</xsl:if>
				<xsl:text>: </xsl:text> 
				<xsl:choose>
					<xsl:when test="@default-type='expression'">
						<span class="expression">/<xsl:value-of select="@default"/>/</span>
					</xsl:when>
					<xsl:otherwise>
						<span class="lit">"<xsl:value-of select="@default"/>"</span>
					</xsl:otherwise>
				</xsl:choose>
				<xsl:text>] </xsl:text>
			</xsl:if>
			<xsl:if test="@optional='false'">
				<xsl:text> </xsl:text>
				<span class="required">[required]</span>
			</xsl:if>
		</li>
	</xsl:template>
	
	<xsl:template match="function">
		<li>Function <var class="function"><xsl:value-of select="@name"/>()</var>
			<xsl:choose>
				<xsl:when test="rgx">
					<ol><xsl:apply-templates select="rgx"/></ol>
				</xsl:when>
				<xsl:otherwise>
					<p><xsl:sequence select="$undefined"/></p>
				</xsl:otherwise>
			</xsl:choose>
		</li>
	</xsl:template>
	
	<xsl:template match="rgx">
		 <li>
		 	<xsl:text>Replace </xsl:text>
		 	<span class="regex">/<xsl:value-of select="@pattern"/>/</span>
		 	<xsl:text> with </xsl:text>
		 	<span class="regex">/<xsl:value-of select="@replace"/>/</span>
		 	<xsl:if test="@mustmatch='true'"> [must match]</xsl:if>
		 </li>
	</xsl:template>
	
	<xsl:template match="variable">
		<xsl:choose>
			<xsl:when test="assign|add|remove">
				<xsl:apply-templates/>
			</xsl:when>
			<xsl:otherwise>
				<li>
					<xsl:text>Variable </xsl:text>
					<var class="variable"><xsl:value-of select="@name"/></var>
					<xsl:text> = </xsl:text>
					<xsl:sequence select="$undefined"/>
				</li>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
		
	<xsl:template match="list">
		<span class="array">
			<xsl:text> { </xsl:text>
			<xsl:for-each select="literal|null|emptystring">
				<xsl:apply-templates select="."/>
				<xsl:if test="position() != last()">, </xsl:if>
			</xsl:for-each>
			<xsl:text> } </xsl:text>
		</span>
	</xsl:template>
	
	<xsl:template match="assign">
		<li>
			<xsl:text>Variable </xsl:text>
			<var class="variable"><xsl:value-of select="../@name"/></var>
			<xsl:text> [</xsl:text>
			<span class="range"><xsl:value-of select="if (@range) then @range else '*'"/></span>
			<xsl:text>] </xsl:text>
			<xsl:text>= </xsl:text>
			<xsl:apply-templates/>
		</li>
	</xsl:template>
	
	<xsl:template match="add">
		<li>
			<xsl:text>Variable </xsl:text>
			<var class="variable"><xsl:value-of select="../@name"/></var>
			<xsl:text> [</xsl:text>
			<span class="range"><xsl:value-of select="if (@range) then @range else '*'"/></span>
			<xsl:text>] </xsl:text>
			<span class="emph-operator">+</span>
			<xsl:text>= </xsl:text>
			<xsl:apply-templates/>
		</li>
	</xsl:template>
	
	<xsl:template match="remove">
		<li>
			<xsl:text>Variable </xsl:text>
			<var class="variable"><xsl:value-of select="../@name"/></var>
			<xsl:text> [</xsl:text>
			<span class="range"><xsl:value-of select="if (@range) then @range else '*'"/></span>
			<xsl:text>] </xsl:text>
			<span class="emph-operator">&#8722;</span>
			<xsl:text>= </xsl:text>
			<xsl:apply-templates/>
		</li>
	</xsl:template>
	
	<xsl:template match="var">
		<var class="variable"><xsl:value-of select="@name"/></var>
	</xsl:template>
	
	<xsl:template match="param">
		<var class="parameter"><xsl:value-of select="@name"/></var>
	</xsl:template>
	
	<xsl:template match="literal">
		<xsl:choose>
			<xsl:when test="@type='expression'">
				<span class="expression">/<xsl:value-of select="@value"/>/</span>
			</xsl:when>
			<xsl:otherwise>
				<span class="lit">"<xsl:value-of select="@value"/>"</span>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="emptystring">
		<span class="null">λ</span>
	</xsl:template>
	
	<xsl:template match="apply-function">
		<var class="function"><xsl:value-of select="@name"/></var>
		<xsl:text> (</xsl:text>
		<xsl:apply-templates/>
		<xsl:text>)</xsl:text>
	</xsl:template>
	
	<xsl:template match="apply-function/concatenation | assign/concatenation | add/concatenation | remove/concatenation">
		<xsl:call-template name="ProcessConcatenation"/>
	</xsl:template>
	
	<xsl:template match="concatenation">
		<strong> ( </strong>
		<xsl:call-template name="ProcessConcatenation"/>
		<strong> ) </strong>
	</xsl:template>
	
	<xsl:template match="apply-function/union | assign/union | add/union | remove/union">
		<xsl:call-template name="ProcessUnion"/>
	</xsl:template>
	
	<xsl:template match="union">
		<strong> ( </strong>
		<xsl:call-template name="ProcessUnion"/>
		<strong> ) </strong>
	</xsl:template>
	
	<xsl:template name="ProcessUnion">
		<xsl:for-each select="*">
			<xsl:apply-templates select="."/>
			<xsl:if test="position() != last()">
				<strong> | </strong>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template name="ProcessConcatenation">
		<xsl:for-each select="*">
			<xsl:apply-templates select="."/>
			<xsl:if test="position() != last()">
				<strong> . </strong>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template match="null">
		<span class="null">NULL</span>
	</xsl:template>
	
	<xsl:template match="when">
		<li>
			<xsl:text>When parameter </xsl:text>
			<var class="parameter"><xsl:value-of select="@parameter"/></var>
			<xsl:text> matches "</xsl:text>
			<xsl:value-of select="@matches"/>
			<xsl:text>":</xsl:text>
			<ul><xsl:apply-templates select="override"/></ul>
		</li>
	</xsl:template>
	
	<xsl:template match="override">
		<xsl:apply-templates/>
	</xsl:template>
	
</xsl:stylesheet>