xslt-examples/relpipe-out-xhtml.xsl
author František Kučera <franta-hg@frantovo.cz>
Sun, 05 Jan 2020 17:02:37 +0100
branchv_0
changeset 25 8e2d9b67b51c
child 27 796ff16f32fc
permissions -rw-r--r--
xslt: a basic XSLT template for XHTML output + helper scripts

<?xml version="1.0" encoding="UTF-8"?>
<!--
Relational pipes
Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<xsl:stylesheet version="1.0"
				xmlns="http://www.w3.org/1999/xhtml"
				xmlns:h="http://www.w3.org/1999/xhtml"
				xmlns:rp="tag:globalcode.info,2018:relpipe"
				xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
				xmlns:fn="http://www.w3.org/2005/xpath-functions"
				xmlns:svg="http://www.w3.org/2000/svg"
				xmlns:xs="http://www.w3.org/2001/XMLSchema"
				exclude-result-prefixes="fn h rp xs">
	<xsl:output
		method="xml"
		indent="yes"
		encoding="UTF-8"
		doctype-public="-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
		doctype-system="http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"/>

	<xsl:param name="title" select="'Relational pipes XHTML output'"/>


	<!--
		TODO:
			Parameters:
				title / h1
				introduction and footer for whole report
				introduction and footer for every relation
				custom CSS + optionaly remove default CSS
				custom JavaScript
				whether to display or hide types in table headers
				whether to insert CSS classes for data types in each <td/>
				custom pre regex (see below)
				metadata relation name (will be hidden and we will get texts or custom titles for particular relations)

			CSS:
				clean-up, better style
				attribute name
				attribute type
				relation name
				table class for each relation (if [a-zA-Z0-9]+)
	-->

	<xsl:template match="/">
		<html>
			<head>
				<title>
					<xsl:value-of select="$title"/>
				</title>
				<meta name="generator" content="Relational pipes: https://relational-pipes.globalcode.info/"/>
				<style type="text/css">
					body {
					font-family: sans;
					background-color: #eee;
					color: black;
					padding-left: 20px;
					}
					
					p {
					max-width: 800px;
					}
					
					h1,h2 {
					max-width: 800px;
					border-radius: 8px;
					border: 1px solid #ddd;
					background-color: #e8e8e8;
					padding: 6px;
					text-shadow: 2px 2px 2px #aaa;
					}
					
					h1 {
					font-size: 150%
					}
					h2 {
					font-size: 100%;
					font-weight: bold;
					}
					
					pre,code {
					color: #a00;
					}
					
					table {
					border-collapse:collapse;
					box-shadow: 3px 3px 3px grey;
					margin-top: 10px;
					margin-bottom: 10px;
					}
					td, th {
					border: 1px solid black;
					padding-top: 4px;
					padding-bottom: 4px;
					padding-left: 6px;
					padding-right: 6px;
					font-weight: normal;
					}
					td.type_integer,td.type_boolean {
					text-align: right;
					}
					thead tr {
					background: #aaa;
					color:black;
					}
					tbody tr:hover {
					background-color: silver;
					color:black;
					}
					
				</style>
			</head>
			<body>
				<h1>
					<xsl:value-of select="$title"/>
				</h1>
				
				<p>
					This is output of <code>relpipe-out-xml</code> converted to XHTML web page.
				</p>
				
				<xsl:for-each select="/rp:relpipe/rp:relation">
					<h2>
						<xsl:value-of select="rp:name"/>
					</h2>
					
					<table>
						<thead>
							<tr>
								<xsl:for-each select="rp:attributes-metadata/rp:attribute-metadata">
									<td>
										<xsl:value-of select="@name"/>
										<xsl:text> (</xsl:text>
										<xsl:value-of select="@type"/>
										<xsl:text>)</xsl:text>
									</td>
								</xsl:for-each>
							</tr>
						</thead>
						<tbody>
							<xsl:for-each select="rp:record">
								<tr>
									<xsl:for-each select="rp:attribute">
										<xsl:variable name="column" select="position()"/>
										<!-- TODO: wrap in <pre/> for relations/attributes matching a regular expression passed as a XSLT parameter e.g. „relation1:attribute1|relation2:attribute3“  -->
										<td class="type_{../../rp:attributes-metadata/rp:attribute-metadata[$column]/@type}">
											<xsl:apply-templates/>
										</td>
									</xsl:for-each>
								</tr>
							</xsl:for-each>
						</tbody>
					</table>
					
				</xsl:for-each>

			</body>
		</html>
	</xsl:template>

</xsl:stylesheet>