helpers/mimeXhtmlPart.xsl
author František Kučera <franta-hg@frantovo.cz>
Wed, 31 Dec 2014 12:07:40 +0100
changeset 120 bb1c8a7b774c
parent 116 4ddc1020a154
permissions -rwxr-xr-x
XSLT: licence – GNU GPLv3
franta-hg@76
     1
<?xml version="1.0" encoding="UTF-8"?>
franta-hg@120
     2
<!--
franta-hg@120
     3
Copyright © 2014 František Kučera (frantovo.cz)
franta-hg@120
     4
franta-hg@120
     5
This program is free software: you can redistribute it and/or modify
franta-hg@120
     6
it under the terms of the GNU General Public License as published by
franta-hg@120
     7
the Free Software Foundation, either version 3 of the License, or
franta-hg@120
     8
(at your option) any later version.
franta-hg@120
     9
franta-hg@120
    10
This program is distributed in the hope that it will be useful,
franta-hg@120
    11
but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@120
    12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
franta-hg@120
    13
GNU General Public License for more details.
franta-hg@120
    14
franta-hg@120
    15
You should have received a copy of the GNU General Public License
franta-hg@120
    16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
franta-hg@120
    17
-->
franta-hg@77
    18
<xsl:stylesheet version="2.0"
franta-hg@76
    19
	xmlns="http://www.w3.org/1999/xhtml"
franta-hg@76
    20
	xmlns:h="http://www.w3.org/1999/xhtml"
franta-hg@76
    21
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
franta-hg@76
    22
	xmlns:fn="http://www.w3.org/2005/xpath-functions"
franta-hg@76
    23
	xmlns:svg="http://www.w3.org/2000/svg"
franta-hg@76
    24
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
franta-hg@76
    25
	exclude-result-prefixes="fn h xs">
franta-hg@76
    26
	<xsl:output 
franta-hg@76
    27
		method="xml" 
franta-hg@76
    28
		indent="yes" 
franta-hg@76
    29
		encoding="UTF-8"		
franta-hg@88
    30
		doctype-public="-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"/><!-- 
franta-hg@88
    31
		doctype-system="http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"/>-->
franta-hg@76
    32
	
franta-hg@76
    33
		
franta-hg@76
    34
	<xsl:param name="title"/>
franta-hg@83
    35
	<xsl:param name="headComment"/>
franta-hg@76
    36
	<xsl:param name="isRoot"/>
franta-hg@76
    37
	<xsl:param name="urlBase"/>
franta-hg@76
    38
	<xsl:param name="wwwRead"/>
franta-hg@76
    39
	<xsl:param name="wwwPost"/>
franta-hg@76
    40
	
franta-hg@76
    41
	
franta-hg@76
    42
	<!-- Celý dokument -->
franta-hg@76
    43
	<xsl:template match="/">
franta-hg@76
    44
		<html>
franta-hg@76
    45
			<head>
franta-hg@76
    46
				<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
franta-hg@76
    47
				<xsl:if test="$urlBase">
franta-hg@76
    48
					<base href="{$urlBase}"/>
franta-hg@76
    49
				</xsl:if>
franta-hg@76
    50
				<xsl:if test="$title">
franta-hg@76
    51
					<title><xsl:value-of select="$title"/></title>
franta-hg@76
    52
				</xsl:if>
franta-hg@83
    53
				<xsl:if test="$headComment">
franta-hg@83
    54
					<xsl:comment><xsl:value-of select="$headComment"/></xsl:comment>
franta-hg@83
    55
				</xsl:if>
franta-hg@76
    56
				<style type="text/css">
franta-hg@76
    57
					body {
franta-hg@76
    58
						font-family: sans-serif;
franta-hg@76
    59
						font-size: 16px;
franta-hg@76
    60
					}
franta-hg@76
    61
					
franta-hg@76
    62
					.wwwLinks {
franta-hg@76
    63
						border-top: 2px solid grey;
franta-hg@76
    64
						margin-top: 16px;
franta-hg@76
    65
						font-size: 66%;
franta-hg@76
    66
					}
franta-hg@76
    67
					
franta-hg@76
    68
					blockquote {
franta-hg@76
    69
						background-color: #eee;
franta-hg@76
    70
						font-style: italic;
franta-hg@76
    71
						padding: 2px 20px;
franta-hg@76
    72
						margin: 10px 32px;
franta-hg@76
    73
						border-left: 3px solid silver;
franta-hg@76
    74
					}
franta-hg@76
    75
					
franta-hg@76
    76
					pre {
franta-hg@76
    77
						background-color: #eee;
franta-hg@76
    78
						padding: 2px 20px;
franta-hg@76
    79
						margin: 10px 32px;
franta-hg@76
    80
						border-left: 3px solid #a00;
franta-hg@76
    81
					}
franta-hg@76
    82
					
franta-hg@76
    83
					img {
franta-hg@76
    84
						margin: 8px;
franta-hg@76
    85
					}
franta-hg@76
    86
					
franta-hg@76
    87
					a img {
franta-hg@76
    88
						border: none;
franta-hg@76
    89
					}
franta-hg@76
    90
				</style>
franta-hg@76
    91
			</head>
franta-hg@76
    92
			<body>
franta-hg@76
    93
				<xsl:if test="$title and $isRoot">
franta-hg@120
    94
					<h1><xsl:value-of select="$title"/></h1>
franta-hg@76
    95
				</xsl:if>
franta-hg@83
    96
								
franta-hg@83
    97
				<xsl:apply-templates select="h:html/h:body"/>
franta-hg@76
    98
				
franta-hg@76
    99
				<xsl:if test="$wwwRead or $wwwPost">
franta-hg@76
   100
					<div class="wwwLinks">
franta-hg@76
   101
						<p>Přístup přes síť www:</p>
franta-hg@76
   102
						<ul>
franta-hg@76
   103
							<xsl:if test="$wwwRead"><li><a href="{$wwwRead}">číst tento příspěvek</a></li></xsl:if>
franta-hg@76
   104
							<xsl:if test="$wwwPost"><li><a href="{$wwwPost}">odpovědět na tento příspěvek</a></li></xsl:if>
franta-hg@76
   105
						</ul>
franta-hg@76
   106
					</div>
franta-hg@76
   107
				</xsl:if>
franta-hg@76
   108
			</body>
franta-hg@76
   109
		</html>
franta-hg@76
   110
	</xsl:template>
franta-hg@76
   111
	
franta-hg@76
   112
	
franta-hg@76
   113
	<!-- Odkazy -->
franta-hg@76
   114
	<xsl:template match="h:a">
franta-hg@94
   115
		<xsl:element name="a">
franta-hg@94
   116
			<xsl:if test="@href"><xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute></xsl:if>
franta-hg@94
   117
			<xsl:if test="@title"><xsl:attribute name="title"><xsl:value-of select="@title"/></xsl:attribute></xsl:if>
franta-hg@94
   118
			<xsl:if test="@id"><xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute></xsl:if>
franta-hg@94
   119
			<xsl:apply-templates select="node()"/>
franta-hg@94
   120
		</xsl:element>
franta-hg@76
   121
	</xsl:template>
franta-hg@76
   122
	
franta-hg@76
   123
	
franta-hg@76
   124
	<!-- Obrázky -->
franta-hg@76
   125
	<xsl:template match="h:img">
franta-hg@94
   126
		<xsl:element name="img">
franta-hg@94
   127
			<xsl:if test="@src"><xsl:attribute name="src"><xsl:value-of select="@src"/></xsl:attribute></xsl:if>
franta-hg@94
   128
			<xsl:if test="@title"><xsl:attribute name="title"><xsl:value-of select="@title"/></xsl:attribute></xsl:if>
franta-hg@94
   129
			<xsl:if test="@alt"><xsl:attribute name="alt"><xsl:value-of select="@alt"/></xsl:attribute></xsl:if>
franta-hg@94
   130
		</xsl:element>
franta-hg@76
   131
	</xsl:template>
franta-hg@76
   132
	
franta-hg@94
   133
	
franta-hg@76
   134
	<!-- Zkratky -->
franta-hg@76
   135
	<xsl:template match="h:abbr">
franta-hg@76
   136
		<abbr title="{@title}"><xsl:apply-templates/></abbr>
franta-hg@76
   137
	</xsl:template>
franta-hg@76
   138
	
franta-hg@94
   139
	
franta-hg@94
   140
	<!-- Citace -->
franta-hg@90
   141
	<xsl:template match="h:blockquote[not(h:p)]">
franta-hg@90
   142
		<blockquote>
franta-hg@90
   143
			<p>
franta-hg@90
   144
				<xsl:copy-of select="node()"/>
franta-hg@90
   145
			</p>
franta-hg@90
   146
		</blockquote>
franta-hg@90
   147
	</xsl:template>
franta-hg@90
   148
	
franta-hg@116
   149
	
franta-hg@94
   150
	<!-- Tučné písmo -->
franta-hg@94
   151
	<xsl:template match="h:b">
franta-hg@94
   152
		<strong>
franta-hg@94
   153
			<xsl:apply-templates select="node()"/>
franta-hg@94
   154
		</strong>
franta-hg@94
   155
	</xsl:template>
franta-hg@76
   156
	
franta-hg@116
   157
	
franta-hg@94
   158
	<!-- Skloněné písmo -->
franta-hg@94
   159
	<xsl:template match="h:i">
franta-hg@94
   160
		<em>
franta-hg@94
   161
			<xsl:apply-templates select="node()"/>
franta-hg@94
   162
		</em>
franta-hg@94
   163
	</xsl:template>
franta-hg@94
   164
	
franta-hg@94
   165
	
franta-hg@116
   166
	<!-- Markdown dává do pre ještě code – to ale nepotřebujeme, stačí nám pre a v něm rovnou text -->
franta-hg@116
   167
	<xsl:template match="h:pre[h:code]">
franta-hg@116
   168
		<pre><xsl:apply-templates select="h:code/node()"/></pre>
franta-hg@116
   169
	</xsl:template>
franta-hg@116
   170
	
franta-hg@116
   171
	
franta-hg@94
   172
	<!--
franta-hg@94
   173
		Další povolené značky (jejich případné atributy zahodíme).
franta-hg@94
   174
		Ostatní elementy odfiltrujeme (zbude z nich jen text). 
franta-hg@94
   175
	-->
franta-hg@76
   176
	<xsl:template match="*">
franta-hg@76
   177
		<xsl:choose>		
franta-hg@76
   178
			<xsl:when test="
franta-hg@76
   179
				name() = 'h1' or
franta-hg@76
   180
				name() = 'h2' or
franta-hg@76
   181
				name() = 'h3' or
franta-hg@76
   182
				name() = 'h4' or
franta-hg@76
   183
				name() = 'h5' or
franta-hg@76
   184
				name() = 'h6' or
franta-hg@76
   185
				name() = 'p' or
franta-hg@76
   186
				name() = 'div' or
franta-hg@76
   187
				name() = 'br' or
franta-hg@88
   188
				name() = 'hr' or
franta-hg@76
   189
				name() = 'strong' or
franta-hg@76
   190
				name() = 'em' or
franta-hg@76
   191
				name() = 'sub' or
franta-hg@76
   192
				name() = 'sup' or
franta-hg@76
   193
				name() = 'del' or
franta-hg@76
   194
				name() = 'ul' or
franta-hg@76
   195
				name() = 'ol' or
franta-hg@76
   196
				name() = 'li' or
franta-hg@76
   197
				name() = 'pre' or
franta-hg@76
   198
				name() = 'code' or
franta-hg@97
   199
				name() = 'cite' or
franta-hg@76
   200
				name() = 'blockquote'">
franta-hg@76
   201
				<xsl:element name="{name()}">
franta-hg@94
   202
					<xsl:apply-templates select="node()"/>
franta-hg@76
   203
				</xsl:element>
franta-hg@76
   204
			</xsl:when>
franta-hg@76
   205
			<xsl:otherwise>
franta-hg@83
   206
				<xsl:apply-templates/>
franta-hg@76
   207
			</xsl:otherwise>
franta-hg@76
   208
		</xsl:choose>		
franta-hg@76
   209
    </xsl:template>
franta-hg@77
   210
	
franta-hg@76
   211
</xsl:stylesheet>