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