xslt: relpipe-out-xhtml: customizable strings and CSS
This commands now accepts following parameters:
--title
--css-appendix
--description
--record-count-prefix
--record-count-suffix
--relation-name-prefix
--relation-name-suffix
and allows to customize (e.g. localize) the XHTML output or override CSS rules by providing own.
Attribute names, types and record counts have CSS classes and can be styled or (visually) removed.
<?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'"/>
<xsl:param name="description">This is output of <code>relpipe-out-xml</code> converted to XHTML web page.</xsl:param>
<xsl:param name="recordCountPrefix">Record count: </xsl:param>
<xsl:param name="recordCountSuffix"></xsl:param>
<xsl:param name="relationNamePrefix"></xsl:param>
<xsl:param name="relationNameSuffix"></xsl:param>
<xsl:param name="cssAppendix"></xsl:param>
<!--
TODO:
Parameters:
custom JavaScript
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:
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: "Latin Modern Sans", sans;
background-color: #efefef;
color: black;
padding-left: 20px;
}
p {
max-width: 1200px;
}
h1 {
font-size: 160%;
font-weight: bolder;
}
h2 {
font-size: 130%;
font-weight: bolder;
}
code {
font-family: "Latin Modern Mono", "Dejavu Sans Mono", monospace;
}
pre,code {
font-family: "Latin Modern Mono", "Dejavu Sans Mono", monospace;
}
table {
border-collapse:collapse;
margin-top: 10px;
margin-bottom: 10px;
box-shadow: 3px 3px 2px 0px rgba(0,0,0,0.2);
}
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;
}
<xsl:value-of select="$cssAppendix"/>
</style>
</head>
<body>
<h1>
<xsl:value-of select="$title"/>
</h1>
<p class="description">
<xsl:copy-of select="$description"/>
</p>
<xsl:for-each select="/rp:relpipe/rp:relation">
<h2>
<xsl:copy-of select="$relationNamePrefix"/>
<xsl:value-of select="rp:name"/>
<xsl:copy-of select="$relationNameSuffix"/>
</h2>
<table>
<thead>
<tr>
<xsl:for-each select="rp:attributes-metadata/rp:attribute-metadata">
<td>
<span class="attributeName">
<xsl:value-of select="@name"/>
</span>
<span class="attributeType">
<xsl:text> (</xsl:text>
<xsl:value-of select="@type"/>
<xsl:text>)</xsl:text>
</span>
</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>
<p class="recordCount">
<xsl:copy-of select="$recordCountPrefix"/>
<span class="recordCount">
<xsl:value-of select="count(rp:record)"/>
</span>
<xsl:copy-of select="$recordCountSuffix"/>
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>