view html.xsl @ 12:79dfd9765a67

I *really* should commit more often.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 04 Oct 2011 11:45:04 +0200
parents b3644dff344c
children 2925b0e246c6
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:choose>
			<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 match="o:params">
		<table>
			<tr>
				<th>Type</th>
				<x:if test="o:param/@name"><th>Name</th></x:if>
				<x:if test="o:param/@unit"><th>Unit</th></x:if>
				<x:if test="o:param/@var"><th>Variable</th></x:if>
				<x:if test="o:param != ''"><th>Notes</th></x:if>
				<x:if test="o:param/@values"><th>Values</th></x:if>
			</tr>
			<x:apply-templates select="o:param"/>
		</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">
		<x:choose>
			<x:when test="count(*) &gt; 1">
				<x:apply-templates/>
			</x:when>
			<x:otherwise>
				<p><x:apply-templates/></p>
			</x:otherwise>
		</x:choose>
	</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>