view html.xsl @ 13:2925b0e246c6 default tip

Fix a lot of things, and add a TODO.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 17 Feb 2012 12:54:08 +0100
parents 79dfd9765a67
children
line wrap: on
line source

<?xml version="1.0" encoding="utf-8"?>
<x:stylesheet version="1.0"
	exclude-result-prefixes="o h"
	xmlns:x="http://www.w3.org/1999/XSL/Transform"
	xmlns:o="urn:opcodes:description"
	xmlns:h="http://www.w3.org/1999/xhtml"
	xmlns="http://www.w3.org/1999/xhtml">

	<x:output encoding="utf-8" indent="yes" method="xml" />

	<x:template match="/o:opcodes">
		<html>
			<head>
				<title><x:value-of select="o:title"/></title>
			</head>
			<body>
				<h1><x:value-of select="o:title"/></h1>

				<x:for-each select="o:text/h:div/*">
					<x:call-template name="xhtml"/>
				</x:for-each>

				<x:apply-templates select="o:op"/>
			</body>
		</html>
	</x:template>

	<x:template match="o:op">
		<h3 id="i{o:num}">
			<x:value-of select="o:num"/>
			<x:if test="o:name != ''">
				<x:text> - </x:text><small><x:value-of select="o:name"/></small>
			</x:if>
		</h3>
		
		<x:variable name="ref" select="o:params/@ref"/>
		<x:choose>
			<x:when test="o:params/@ref">
				<x:call-template name="params">
					<x:with-param name="params" select="/o:opcodes/o:op[o:num = $ref]/o:params/o:param"/>
				</x:call-template>
			</x:when>
			<x:when test="o:params">
				<x:apply-templates select="o:params"/>
			</x:when>
			<x:otherwise>
				<p>Takes no parameters.</p>
			</x:otherwise>
		</x:choose>

		<x:apply-templates select="o:desc"/>
	</x:template>

	<x:template name="params" match="o:params">
		<x:param name="params" select="o:param"/>
		<table>
			<tr>
				<th>Type</th>
				<x:if test="$params/@name"><th>Name</th></x:if>
				<x:if test="$params/@unit"><th>Unit</th></x:if>
				<x:if test="$params/@var"><th>Variable</th></x:if>
				<x:if test="$params != ''"><th>Notes</th></x:if>
				<x:if test="$params/@values"><th>Values</th></x:if>
			</tr>
			<x:apply-templates select="$params"/>
		</table>
	</x:template>

	<x:template match="o:param">
		<tr>
			<td><x:apply-templates select="@type"/></td>
			<x:if test="../o:param/@name">
				<td><x:value-of select="@name"/></td>
			</x:if>
			<x:if test="../o:param/@unit">
				<td><x:value-of select="@unit"/></td>
			</x:if>
			<x:if test="../o:param/@var">
				<td><x:value-of select="@var"/></td>
			</x:if>
			<x:if test="../o:param != ''">
				<td><x:value-of select="."/></td>
			</x:if>
			<x:if test="../o:param/@values">
				<td><x:value-of select="@values"/></td>
			</x:if>
		</tr>
	</x:template>

	<x:template match="@type">
		<x:choose>
			<x:when test=". = 'c'">int8</x:when>
			<x:when test=". = 's'">int16</x:when>
			<x:when test=". = 'S'">int32</x:when>
			<x:when test=". = 'b'">uint8</x:when>
			<x:when test=". = 'u'">uint16</x:when>
			<x:when test=". = 'U'">uint32</x:when>
			<x:when test=". = 'f'">float</x:when>
			<x:when test=". = 'd'">double</x:when>
			<x:when test=". = 'z'">string</x:when>
			<x:when test=". = 'm'">data</x:when>
			<x:otherwise><x:value-of select="."/></x:otherwise>
		</x:choose>
	</x:template>

	<x:template match="o:desc">
		<p>
		<x:choose>
			<x:when test="h:div">
				<x:for-each select="h:div/*">
					<x:call-template name="xhtml"/>
				</x:for-each>
			</x:when>
			<x:otherwise>
				<x:apply-templates/>
			</x:otherwise>
		</x:choose>
		</p>
	</x:template>

	<x:template name="xhtml" match="node() | @*">
		<x:copy>
			<x:apply-templates select="node() | @*" />
		</x:copy>
	</x:template>

	<x:template match="o:p"><p><x:apply-templates/></p></x:template>
	<x:template match="o:pre"><pre><x:apply-templates/></pre></x:template>
	<x:template match="o:br"><br/></x:template>

	<x:template match="o:dl"><dl><x:apply-templates/></dl></x:template>
	<x:template match="o:dt"><dt><x:apply-templates/></dt></x:template>
	<x:template match="o:dd"><dd><x:apply-templates/></dd></x:template>

	<x:template match="o:table"><table><x:apply-templates/></table></x:template>
	<x:template match="o:tr"><tr><x:apply-templates/></tr></x:template>
	<x:template match="o:th"><th><x:apply-templates/></th></x:template>
	<x:template match="o:td"><td><x:apply-templates/></td></x:template>

	<x:template match="o:ol"><ol><x:apply-templates/></ol></x:template>
	<x:template match="o:li"><li><x:apply-templates/></li></x:template>

	<x:template match="o:a"><a href="{@href}"><x:apply-templates/></a></x:template>
	<x:template match="o:code"><code><x:apply-templates/></code></x:template>
	<x:template match="o:sup"><sup><x:apply-templates/></sup></x:template>

	<x:template match="o:stage">
		<x:text>stage </x:text><x:value-of select="."/>
	</x:template>

	<x:template match="o:ref">
		<x:variable name="ref" select="."/>
		<a href="#i{$ref}">
			<x:choose>
				<x:when test="/o:opcodes/o:op[o:num = $ref]/o:name = ''">
					<x:text>instruction </x:text><x:value-of select="$ref"/>
				</x:when>
				<x:otherwise>
					<x:value-of select="/o:opcodes/o:op[o:num = $ref]/o:name"/>
				</x:otherwise>
			</x:choose>
		</a>
	</x:template>
</x:stylesheet>