franta-hg@76
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
franta-hg@76
|
2 |
<xsl:stylesheet version="1.0"
|
franta-hg@76
|
3 |
xmlns="http://www.w3.org/1999/xhtml"
|
franta-hg@76
|
4 |
xmlns:h="http://www.w3.org/1999/xhtml"
|
franta-hg@76
|
5 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
franta-hg@76
|
6 |
xmlns:fn="http://www.w3.org/2005/xpath-functions"
|
franta-hg@76
|
7 |
xmlns:svg="http://www.w3.org/2000/svg"
|
franta-hg@76
|
8 |
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
franta-hg@76
|
9 |
exclude-result-prefixes="fn h xs">
|
franta-hg@76
|
10 |
<xsl:output
|
franta-hg@76
|
11 |
method="xml"
|
franta-hg@76
|
12 |
indent="yes"
|
franta-hg@76
|
13 |
encoding="UTF-8"
|
franta-hg@76
|
14 |
doctype-public="-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
|
franta-hg@76
|
15 |
doctype-system="http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"/>
|
franta-hg@76
|
16 |
|
franta-hg@76
|
17 |
|
franta-hg@76
|
18 |
<xsl:param name="title"/>
|
franta-hg@76
|
19 |
<xsl:param name="isRoot"/>
|
franta-hg@76
|
20 |
<xsl:param name="urlBase"/>
|
franta-hg@76
|
21 |
<xsl:param name="wwwRead"/>
|
franta-hg@76
|
22 |
<xsl:param name="wwwPost"/>
|
franta-hg@76
|
23 |
|
franta-hg@76
|
24 |
|
franta-hg@76
|
25 |
<!-- Celý dokument -->
|
franta-hg@76
|
26 |
<xsl:template match="/">
|
franta-hg@76
|
27 |
<html>
|
franta-hg@76
|
28 |
<head>
|
franta-hg@76
|
29 |
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
|
franta-hg@76
|
30 |
<xsl:if test="$urlBase">
|
franta-hg@76
|
31 |
<base href="{$urlBase}"/>
|
franta-hg@76
|
32 |
</xsl:if>
|
franta-hg@76
|
33 |
<xsl:if test="$title">
|
franta-hg@76
|
34 |
<title><xsl:value-of select="$title"/></title>
|
franta-hg@76
|
35 |
</xsl:if>
|
franta-hg@76
|
36 |
<style type="text/css">
|
franta-hg@76
|
37 |
body {
|
franta-hg@76
|
38 |
font-family: sans-serif;
|
franta-hg@76
|
39 |
font-size: 16px;
|
franta-hg@76
|
40 |
}
|
franta-hg@76
|
41 |
|
franta-hg@76
|
42 |
.wwwLinks {
|
franta-hg@76
|
43 |
border-top: 2px solid grey;
|
franta-hg@76
|
44 |
margin-top: 16px;
|
franta-hg@76
|
45 |
font-size: 66%;
|
franta-hg@76
|
46 |
}
|
franta-hg@76
|
47 |
|
franta-hg@76
|
48 |
blockquote {
|
franta-hg@76
|
49 |
background-color: #eee;
|
franta-hg@76
|
50 |
font-style: italic;
|
franta-hg@76
|
51 |
padding: 2px 20px;
|
franta-hg@76
|
52 |
margin: 10px 32px;
|
franta-hg@76
|
53 |
border-left: 3px solid silver;
|
franta-hg@76
|
54 |
}
|
franta-hg@76
|
55 |
|
franta-hg@76
|
56 |
pre {
|
franta-hg@76
|
57 |
background-color: #eee;
|
franta-hg@76
|
58 |
padding: 2px 20px;
|
franta-hg@76
|
59 |
margin: 10px 32px;
|
franta-hg@76
|
60 |
border-left: 3px solid #a00;
|
franta-hg@76
|
61 |
}
|
franta-hg@76
|
62 |
|
franta-hg@76
|
63 |
img {
|
franta-hg@76
|
64 |
margin: 8px;
|
franta-hg@76
|
65 |
}
|
franta-hg@76
|
66 |
|
franta-hg@76
|
67 |
a img {
|
franta-hg@76
|
68 |
border: none;
|
franta-hg@76
|
69 |
}
|
franta-hg@76
|
70 |
</style>
|
franta-hg@76
|
71 |
</head>
|
franta-hg@76
|
72 |
<body>
|
franta-hg@76
|
73 |
<xsl:if test="$title and $isRoot">
|
franta-hg@76
|
74 |
<h1><xsl:value-of select="$title"/></h1>
|
franta-hg@76
|
75 |
</xsl:if>
|
franta-hg@76
|
76 |
<xsl:apply-templates select="h:html/h:body/node()"/>
|
franta-hg@76
|
77 |
|
franta-hg@76
|
78 |
<xsl:if test="$wwwRead or $wwwPost">
|
franta-hg@76
|
79 |
<div class="wwwLinks">
|
franta-hg@76
|
80 |
<p>Přístup přes síť www:</p>
|
franta-hg@76
|
81 |
<ul>
|
franta-hg@76
|
82 |
<xsl:if test="$wwwRead"><li><a href="{$wwwRead}">číst tento příspěvek</a></li></xsl:if>
|
franta-hg@76
|
83 |
<xsl:if test="$wwwPost"><li><a href="{$wwwPost}">odpovědět na tento příspěvek</a></li></xsl:if>
|
franta-hg@76
|
84 |
</ul>
|
franta-hg@76
|
85 |
</div>
|
franta-hg@76
|
86 |
</xsl:if>
|
franta-hg@76
|
87 |
</body>
|
franta-hg@76
|
88 |
</html>
|
franta-hg@76
|
89 |
</xsl:template>
|
franta-hg@76
|
90 |
|
franta-hg@76
|
91 |
|
franta-hg@76
|
92 |
<!-- Odkazy -->
|
franta-hg@76
|
93 |
<xsl:template match="h:a">
|
franta-hg@76
|
94 |
<a href="{@href}" title="{@title}"><xsl:apply-templates/></a>
|
franta-hg@76
|
95 |
</xsl:template>
|
franta-hg@76
|
96 |
|
franta-hg@76
|
97 |
|
franta-hg@76
|
98 |
<!-- Obrázky -->
|
franta-hg@76
|
99 |
<xsl:template match="h:img">
|
franta-hg@76
|
100 |
<img src="{@src}" alt="{@alt}" title="{@title}"><xsl:apply-templates/></img>
|
franta-hg@76
|
101 |
</xsl:template>
|
franta-hg@76
|
102 |
|
franta-hg@76
|
103 |
<!-- Zkratky -->
|
franta-hg@76
|
104 |
<xsl:template match="h:abbr">
|
franta-hg@76
|
105 |
<abbr title="{@title}"><xsl:apply-templates/></abbr>
|
franta-hg@76
|
106 |
</xsl:template>
|
franta-hg@76
|
107 |
|
franta-hg@76
|
108 |
|
franta-hg@76
|
109 |
<!-- Další povolené značky – ostatní odfiltrujeme (zbude z nich jen text) -->
|
franta-hg@76
|
110 |
<xsl:template match="*">
|
franta-hg@76
|
111 |
<xsl:choose>
|
franta-hg@76
|
112 |
<xsl:when test="
|
franta-hg@76
|
113 |
name() = 'h1' or
|
franta-hg@76
|
114 |
name() = 'h2' or
|
franta-hg@76
|
115 |
name() = 'h3' or
|
franta-hg@76
|
116 |
name() = 'h4' or
|
franta-hg@76
|
117 |
name() = 'h5' or
|
franta-hg@76
|
118 |
name() = 'h6' or
|
franta-hg@76
|
119 |
name() = 'p' or
|
franta-hg@76
|
120 |
name() = 'div' or
|
franta-hg@76
|
121 |
name() = 'br' or
|
franta-hg@76
|
122 |
name() = 'strong' or
|
franta-hg@76
|
123 |
name() = 'em' or
|
franta-hg@76
|
124 |
name() = 'sub' or
|
franta-hg@76
|
125 |
name() = 'sup' or
|
franta-hg@76
|
126 |
name() = 'del' or
|
franta-hg@76
|
127 |
name() = 'ul' or
|
franta-hg@76
|
128 |
name() = 'ol' or
|
franta-hg@76
|
129 |
name() = 'li' or
|
franta-hg@76
|
130 |
name() = 'pre' or
|
franta-hg@76
|
131 |
name() = 'code' or
|
franta-hg@76
|
132 |
name() = 'blockquote'">
|
franta-hg@76
|
133 |
<xsl:element name="{name()}">
|
franta-hg@76
|
134 |
<xsl:apply-templates/>
|
franta-hg@76
|
135 |
</xsl:element>
|
franta-hg@76
|
136 |
</xsl:when>
|
franta-hg@76
|
137 |
<xsl:otherwise>
|
franta-hg@76
|
138 |
<xsl:value-of select="."/>
|
franta-hg@76
|
139 |
</xsl:otherwise>
|
franta-hg@76
|
140 |
</xsl:choose>
|
franta-hg@76
|
141 |
</xsl:template>
|
franta-hg@76
|
142 |
|
franta-hg@76
|
143 |
|
franta-hg@76
|
144 |
<!--
|
franta-hg@76
|
145 |
Z neuzavřeného (nevalidně se vyskytujícího v body) textu uděláme odstavce.
|
franta-hg@76
|
146 |
Bohužel nefunguje, když neuzavřený text obsahuje jiné značky (odkazy atd.),
|
franta-hg@76
|
147 |
pak se totiž jedná o dva textové uzly (před značkou a za ní) a vzniknou dva odstavce.
|
franta-hg@76
|
148 |
-->
|
franta-hg@76
|
149 |
<xsl:template match="h:body/text()">
|
franta-hg@76
|
150 |
<xsl:call-template name="makeParagraphs">
|
franta-hg@76
|
151 |
<xsl:with-param name="string" select="."/>
|
franta-hg@76
|
152 |
</xsl:call-template>
|
franta-hg@76
|
153 |
</xsl:template>
|
franta-hg@76
|
154 |
<xsl:variable name="newLinePlaceholder" select="'ߜ'"/>
|
franta-hg@76
|
155 |
<xsl:template name="makeParagraphs">
|
franta-hg@76
|
156 |
<xsl:param name="string" />
|
franta-hg@76
|
157 |
<xsl:call-template name="makeParagraphsInternal">
|
franta-hg@76
|
158 |
<!--
|
franta-hg@76
|
159 |
Konec řádku převedeme na obskurní znak,
|
franta-hg@76
|
160 |
normalizací pročistíme bílé znaky →
|
franta-hg@76
|
161 |
dva obskurní znaky oddělené mezerou pak značí předěl mezi odstavci
|
franta-hg@76
|
162 |
-->
|
franta-hg@76
|
163 |
<xsl:with-param name="string" select="normalize-space(translate(., ' ', $newLinePlaceholder))"/>
|
franta-hg@76
|
164 |
</xsl:call-template>
|
franta-hg@76
|
165 |
</xsl:template>
|
franta-hg@76
|
166 |
<xsl:template name="makeParagraphsInternal">
|
franta-hg@76
|
167 |
<xsl:param name="string" />
|
franta-hg@76
|
168 |
<xsl:if test="ends-with($string, $newLinePlaceholder)"><xsl:comment>končí na $newLinePlaceholder</xsl:comment> </xsl:if>
|
franta-hg@76
|
169 |
<!-- V XSLT 2.0 můžeme použít fn:tokenize -->
|
franta-hg@76
|
170 |
<xsl:param name="delimiter" select="concat($newLinePlaceholder, ' ', $newLinePlaceholder)"/>
|
franta-hg@76
|
171 |
<xsl:choose>
|
franta-hg@76
|
172 |
<xsl:when test="$delimiter and contains($string, $delimiter)">
|
franta-hg@76
|
173 |
<xsl:call-template name="makeParagraph">
|
franta-hg@76
|
174 |
<xsl:with-param name="string" select="substring-before($string, $delimiter)"></xsl:with-param>
|
franta-hg@76
|
175 |
</xsl:call-template>
|
franta-hg@76
|
176 |
<xsl:call-template name="makeParagraphsInternal">
|
franta-hg@76
|
177 |
<xsl:with-param name="string" select="substring-after($string, $delimiter)" />
|
franta-hg@76
|
178 |
<xsl:with-param name="delimiter" select="$delimiter" />
|
franta-hg@76
|
179 |
</xsl:call-template>
|
franta-hg@76
|
180 |
</xsl:when>
|
franta-hg@76
|
181 |
<xsl:otherwise>
|
franta-hg@76
|
182 |
<!--
|
franta-hg@76
|
183 |
Poslední odstavec → zkontrolovat, zda je za ním
|
franta-hg@76
|
184 |
-->
|
franta-hg@76
|
185 |
<xsl:call-template name="makeParagraph">
|
franta-hg@76
|
186 |
<xsl:with-param name="string" select="$string"></xsl:with-param>
|
franta-hg@76
|
187 |
</xsl:call-template>
|
franta-hg@76
|
188 |
</xsl:otherwise>
|
franta-hg@76
|
189 |
</xsl:choose>
|
franta-hg@76
|
190 |
</xsl:template>
|
franta-hg@76
|
191 |
<xsl:template name="makeParagraph">
|
franta-hg@76
|
192 |
<xsl:param name="string" />
|
franta-hg@76
|
193 |
<!-- prázdné textové uzly nás nezajímají – nechceme prázdné odstavce -->
|
franta-hg@76
|
194 |
<xsl:if test="normalize-space($string)">
|
franta-hg@76
|
195 |
<p class="mešuge"><xsl:value-of select="translate($string, $newLinePlaceholder, ' ')" /></p>
|
franta-hg@76
|
196 |
</xsl:if>
|
franta-hg@76
|
197 |
</xsl:template>
|
franta-hg@76
|
198 |
|
franta-hg@76
|
199 |
</xsl:stylesheet>
|