author | František Kučera <franta-hg@frantovo.cz> |
Sun, 16 Oct 2011 20:55:46 +0200 | |
changeset 81 | b51ab80c7a9d |
parent 80 | 1f9e5757caf4 |
child 83 | 668014315a54 |
permissions | -rwxr-xr-x |
franta-hg@76 | 1 |
<?xml version="1.0" encoding="UTF-8"?> |
franta-hg@77 | 2 |
<xsl:stylesheet version="2.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@77 | 30 |
<meta http-equiv="X-NNTP-Generated" content="{fn:current-dateTime()}" /> |
franta-hg@76 | 31 |
<xsl:if test="$urlBase"> |
franta-hg@76 | 32 |
<base href="{$urlBase}"/> |
franta-hg@76 | 33 |
</xsl:if> |
franta-hg@76 | 34 |
<xsl:if test="$title"> |
franta-hg@76 | 35 |
<title><xsl:value-of select="$title"/></title> |
franta-hg@76 | 36 |
</xsl:if> |
franta-hg@76 | 37 |
<style type="text/css"> |
franta-hg@76 | 38 |
body { |
franta-hg@76 | 39 |
font-family: sans-serif; |
franta-hg@76 | 40 |
font-size: 16px; |
franta-hg@76 | 41 |
} |
franta-hg@76 | 42 |
|
franta-hg@76 | 43 |
.wwwLinks { |
franta-hg@76 | 44 |
border-top: 2px solid grey; |
franta-hg@76 | 45 |
margin-top: 16px; |
franta-hg@76 | 46 |
font-size: 66%; |
franta-hg@76 | 47 |
} |
franta-hg@76 | 48 |
|
franta-hg@76 | 49 |
blockquote { |
franta-hg@76 | 50 |
background-color: #eee; |
franta-hg@76 | 51 |
font-style: italic; |
franta-hg@76 | 52 |
padding: 2px 20px; |
franta-hg@76 | 53 |
margin: 10px 32px; |
franta-hg@76 | 54 |
border-left: 3px solid silver; |
franta-hg@76 | 55 |
} |
franta-hg@76 | 56 |
|
franta-hg@76 | 57 |
pre { |
franta-hg@76 | 58 |
background-color: #eee; |
franta-hg@76 | 59 |
padding: 2px 20px; |
franta-hg@76 | 60 |
margin: 10px 32px; |
franta-hg@76 | 61 |
border-left: 3px solid #a00; |
franta-hg@76 | 62 |
} |
franta-hg@76 | 63 |
|
franta-hg@76 | 64 |
img { |
franta-hg@76 | 65 |
margin: 8px; |
franta-hg@76 | 66 |
} |
franta-hg@76 | 67 |
|
franta-hg@76 | 68 |
a img { |
franta-hg@76 | 69 |
border: none; |
franta-hg@76 | 70 |
} |
franta-hg@77 | 71 |
|
franta-hg@77 | 72 |
/** TODO: smazat */ |
franta-hg@77 | 73 |
.mešuge { |
franta-hg@77 | 74 |
background-color: #afa; |
franta-hg@81 | 75 |
border: 1px solid #55f; |
franta-hg@77 | 76 |
} |
franta-hg@76 | 77 |
</style> |
franta-hg@76 | 78 |
</head> |
franta-hg@76 | 79 |
<body> |
franta-hg@76 | 80 |
<xsl:if test="$title and $isRoot"> |
franta-hg@76 | 81 |
<h1><xsl:value-of select="$title"/></h1> |
franta-hg@76 | 82 |
</xsl:if> |
franta-hg@78 | 83 |
<xsl:call-template name="zpracujTělo"> |
franta-hg@78 | 84 |
<xsl:with-param name="prvek" select="h:html/h:body/node()[1]"/> |
franta-hg@78 | 85 |
</xsl:call-template> |
franta-hg@76 | 86 |
|
franta-hg@76 | 87 |
<xsl:if test="$wwwRead or $wwwPost"> |
franta-hg@76 | 88 |
<div class="wwwLinks"> |
franta-hg@76 | 89 |
<p>Přístup přes síť www:</p> |
franta-hg@76 | 90 |
<ul> |
franta-hg@76 | 91 |
<xsl:if test="$wwwRead"><li><a href="{$wwwRead}">číst tento příspěvek</a></li></xsl:if> |
franta-hg@76 | 92 |
<xsl:if test="$wwwPost"><li><a href="{$wwwPost}">odpovědět na tento příspěvek</a></li></xsl:if> |
franta-hg@76 | 93 |
</ul> |
franta-hg@76 | 94 |
</div> |
franta-hg@76 | 95 |
</xsl:if> |
franta-hg@76 | 96 |
</body> |
franta-hg@76 | 97 |
</html> |
franta-hg@76 | 98 |
</xsl:template> |
franta-hg@76 | 99 |
|
franta-hg@76 | 100 |
|
franta-hg@76 | 101 |
<!-- Odkazy --> |
franta-hg@76 | 102 |
<xsl:template match="h:a"> |
franta-hg@76 | 103 |
<a href="{@href}" title="{@title}"><xsl:apply-templates/></a> |
franta-hg@76 | 104 |
</xsl:template> |
franta-hg@76 | 105 |
|
franta-hg@76 | 106 |
|
franta-hg@76 | 107 |
<!-- Obrázky --> |
franta-hg@76 | 108 |
<xsl:template match="h:img"> |
franta-hg@76 | 109 |
<img src="{@src}" alt="{@alt}" title="{@title}"><xsl:apply-templates/></img> |
franta-hg@76 | 110 |
</xsl:template> |
franta-hg@76 | 111 |
|
franta-hg@76 | 112 |
<!-- Zkratky --> |
franta-hg@76 | 113 |
<xsl:template match="h:abbr"> |
franta-hg@76 | 114 |
<abbr title="{@title}"><xsl:apply-templates/></abbr> |
franta-hg@76 | 115 |
</xsl:template> |
franta-hg@76 | 116 |
|
franta-hg@76 | 117 |
|
franta-hg@76 | 118 |
<!-- Další povolené značky – ostatní odfiltrujeme (zbude z nich jen text) --> |
franta-hg@76 | 119 |
<xsl:template match="*"> |
franta-hg@76 | 120 |
<xsl:choose> |
franta-hg@76 | 121 |
<xsl:when test=" |
franta-hg@76 | 122 |
name() = 'h1' or |
franta-hg@76 | 123 |
name() = 'h2' or |
franta-hg@76 | 124 |
name() = 'h3' or |
franta-hg@76 | 125 |
name() = 'h4' or |
franta-hg@76 | 126 |
name() = 'h5' or |
franta-hg@76 | 127 |
name() = 'h6' or |
franta-hg@76 | 128 |
name() = 'p' or |
franta-hg@76 | 129 |
name() = 'div' or |
franta-hg@76 | 130 |
name() = 'br' or |
franta-hg@76 | 131 |
name() = 'strong' or |
franta-hg@76 | 132 |
name() = 'em' or |
franta-hg@76 | 133 |
name() = 'sub' or |
franta-hg@76 | 134 |
name() = 'sup' or |
franta-hg@76 | 135 |
name() = 'del' or |
franta-hg@76 | 136 |
name() = 'ul' or |
franta-hg@76 | 137 |
name() = 'ol' or |
franta-hg@76 | 138 |
name() = 'li' or |
franta-hg@76 | 139 |
name() = 'pre' or |
franta-hg@76 | 140 |
name() = 'code' or |
franta-hg@76 | 141 |
name() = 'blockquote'"> |
franta-hg@76 | 142 |
<xsl:element name="{name()}"> |
franta-hg@76 | 143 |
<xsl:apply-templates/> |
franta-hg@76 | 144 |
</xsl:element> |
franta-hg@76 | 145 |
</xsl:when> |
franta-hg@76 | 146 |
<xsl:otherwise> |
franta-hg@76 | 147 |
<xsl:value-of select="."/> |
franta-hg@76 | 148 |
</xsl:otherwise> |
franta-hg@76 | 149 |
</xsl:choose> |
franta-hg@76 | 150 |
</xsl:template> |
franta-hg@76 | 151 |
|
franta-hg@76 | 152 |
<!-- |
franta-hg@76 | 153 |
Z neuzavřeného (nevalidně se vyskytujícího v body) textu uděláme odstavce. |
franta-hg@76 | 154 |
--> |
franta-hg@78 | 155 |
<xsl:template name="zpracujTělo"> |
franta-hg@78 | 156 |
<xsl:param name="prvek"/> |
franta-hg@80 | 157 |
<xsl:param name="vnořeno" select="false()"/> |
franta-hg@78 | 158 |
<xsl:if test="$prvek"> |
franta-hg@79 | 159 |
<xsl:choose> |
franta-hg@79 | 160 |
<xsl:when test="$prvek/self::text()"> |
franta-hg@79 | 161 |
<!-- |
franta-hg@79 | 162 |
Textový uzel → budeme dělat odstavce |
franta-hg@79 | 163 |
(rekurzivně se opět zavolá šablona zpracujTělo) |
franta-hg@79 | 164 |
--> |
franta-hg@81 | 165 |
<xsl:call-template name="dělejOdstavce"> |
franta-hg@79 | 166 |
<xsl:with-param name="blokTextu" select="$prvek"/> |
franta-hg@80 | 167 |
<xsl:with-param name="vnořeno" select="$vnořeno"/> |
franta-hg@79 | 168 |
</xsl:call-template> |
franta-hg@80 | 169 |
|
franta-hg@81 | 170 |
<!-- |
franta-hg@80 | 171 |
<xsl:variable name="navázat" as="xs:boolean"> |
franta-hg@80 | 172 |
<xsl:call-template name="navázat"> |
franta-hg@80 | 173 |
<xsl:with-param name="blokTextu" select="$prvek"/> |
franta-hg@80 | 174 |
</xsl:call-template> |
franta-hg@80 | 175 |
</xsl:variable> |
franta-hg@80 | 176 |
|
franta-hg@81 | 177 |
Někdy zpracujTělo dalšího prvku |
franta-hg@81 | 178 |
<xsl:if test="not($navázat)">[další:] |
franta-hg@81 | 179 |
<xsl:call-template name="zpracujTělo"> |
franta-hg@81 | 180 |
<xsl:with-param name="prvek" select="$prvek/following-sibling::node()[1]"/> |
franta-hg@81 | 181 |
<xsl:with-param name="vnořeno" select="$vnořeno"/> |
franta-hg@81 | 182 |
</xsl:call-template> |
franta-hg@81 | 183 |
</xsl:if> |
franta-hg@81 | 184 |
--> |
franta-hg@80 | 185 |
|
franta-hg@79 | 186 |
</xsl:when> |
franta-hg@79 | 187 |
<xsl:otherwise> |
franta-hg@79 | 188 |
<!-- |
franta-hg@79 | 189 |
Jiný uzel → aplikujeme obecné šablony |
franta-hg@79 | 190 |
a zpracujeme následující uzel. |
franta-hg@79 | 191 |
--> |
franta-hg@79 | 192 |
<xsl:apply-templates select="$prvek"/> |
franta-hg@79 | 193 |
<xsl:call-template name="zpracujTělo"> |
franta-hg@79 | 194 |
<xsl:with-param name="prvek" select="$prvek/following-sibling::node()[1]"/> |
franta-hg@80 | 195 |
<xsl:with-param name="vnořeno" select="$vnořeno"/> |
franta-hg@79 | 196 |
</xsl:call-template> |
franta-hg@79 | 197 |
</xsl:otherwise> |
franta-hg@79 | 198 |
</xsl:choose> |
franta-hg@78 | 199 |
</xsl:if> |
franta-hg@76 | 200 |
</xsl:template> |
franta-hg@78 | 201 |
|
franta-hg@81 | 202 |
<xsl:variable name="oddělovač" select="'\n\s*\n\s*'"/> |
franta-hg@80 | 203 |
|
franta-hg@80 | 204 |
<xsl:template name="navázat" as="xs:boolean"> |
franta-hg@80 | 205 |
<xsl:param name="blokTextu"/> |
franta-hg@80 | 206 |
<xsl:variable name="dalšíUzel" select="$blokTextu/following-sibling::node()[1]"/> |
franta-hg@80 | 207 |
<xsl:sequence select=" |
franta-hg@80 | 208 |
not(fn:matches($blokTextu, concat('.*', $oddělovač ,'$'))) and |
franta-hg@80 | 209 |
$dalšíUzel and |
franta-hg@80 | 210 |
not( |
franta-hg@80 | 211 |
$dalšíUzel/name() = 'p' or |
franta-hg@80 | 212 |
$dalšíUzel/name() = 'div' or |
franta-hg@80 | 213 |
$dalšíUzel/name() = 'h1' or |
franta-hg@80 | 214 |
$dalšíUzel/name() = 'h2' or |
franta-hg@80 | 215 |
$dalšíUzel/name() = 'h3' or |
franta-hg@80 | 216 |
$dalšíUzel/name() = 'h4' or |
franta-hg@80 | 217 |
$dalšíUzel/name() = 'h5' or |
franta-hg@80 | 218 |
$dalšíUzel/name() = 'h6' or |
franta-hg@80 | 219 |
$dalšíUzel/name() = 'pre' or |
franta-hg@80 | 220 |
$dalšíUzel/name() = 'table' or |
franta-hg@80 | 221 |
$dalšíUzel/name() = 'blockquote' or |
franta-hg@80 | 222 |
$dalšíUzel/name() = 'hr' |
franta-hg@80 | 223 |
) |
franta-hg@80 | 224 |
"/> |
franta-hg@80 | 225 |
</xsl:template> |
franta-hg@80 | 226 |
|
franta-hg@81 | 227 |
<xsl:template name="dělejOdstavce"> |
franta-hg@79 | 228 |
<xsl:param name="blokTextu"/> |
franta-hg@80 | 229 |
<xsl:param name="vnořeno" select="false()"/> |
franta-hg@80 | 230 |
|
franta-hg@79 | 231 |
<xsl:variable name="dalšíUzel" select="$blokTextu/following-sibling::node()[1]"/> |
franta-hg@79 | 232 |
|
franta-hg@80 | 233 |
<xsl:variable name="navázat" as="xs:boolean"> |
franta-hg@80 | 234 |
<xsl:call-template name="navázat"> |
franta-hg@80 | 235 |
<xsl:with-param name="blokTextu" select="$blokTextu"/> |
franta-hg@80 | 236 |
</xsl:call-template> |
franta-hg@80 | 237 |
</xsl:variable> |
franta-hg@79 | 238 |
|
franta-hg@79 | 239 |
<xsl:for-each select="fn:tokenize($blokTextu, $oddělovač)"> |
franta-hg@81 | 240 |
<!-- TODO: ošetřit prázdné odstavce --> |
franta-hg@81 | 241 |
<xsl:if test="normalize-space(.) or true()"> |
franta-hg@80 | 242 |
<xsl:choose> |
franta-hg@80 | 243 |
<xsl:when test="$vnořeno"> |
franta-hg@81 | 244 |
[ |
franta-hg@80 | 245 |
<xsl:value-of select="."/> |
franta-hg@80 | 246 |
<xsl:if test="$navázat and position() = last()"> |
franta-hg@81 | 247 |
→ |
franta-hg@80 | 248 |
<xsl:call-template name="zpracujTělo"> |
franta-hg@80 | 249 |
<xsl:with-param name="prvek" select="$dalšíUzel"/> |
franta-hg@80 | 250 |
<xsl:with-param name="vnořeno" select="true()"/> |
franta-hg@80 | 251 |
</xsl:call-template> |
franta-hg@80 | 252 |
</xsl:if> |
franta-hg@81 | 253 |
] |
franta-hg@81 | 254 |
[Avril:] |
franta-hg@81 | 255 |
<xsl:if test="not($navázat) and position() = last()"> |
franta-hg@81 | 256 |
a→ |
franta-hg@81 | 257 |
<xsl:call-template name="zpracujTělo"> |
franta-hg@81 | 258 |
<xsl:with-param name="prvek" select="$dalšíUzel"/> |
franta-hg@81 | 259 |
<xsl:with-param name="vnořeno" select="true()"/> |
franta-hg@81 | 260 |
</xsl:call-template> |
franta-hg@81 | 261 |
</xsl:if> |
franta-hg@81 | 262 |
</xsl:when> |
franta-hg@81 | 263 |
<xsl:otherwise> |
franta-hg@81 | 264 |
<p class="mešuge"> |
franta-hg@81 | 265 |
{ |
franta-hg@81 | 266 |
<xsl:value-of select="."/> |
franta-hg@81 | 267 |
<xsl:if test="$navázat and position() = last()"> |
franta-hg@81 | 268 |
s→ |
franta-hg@81 | 269 |
<xsl:call-template name="zpracujTělo"> |
franta-hg@81 | 270 |
<xsl:with-param name="prvek" select="$dalšíUzel"/> |
franta-hg@81 | 271 |
<xsl:with-param name="vnořeno" select="true()"/> |
franta-hg@81 | 272 |
</xsl:call-template> |
franta-hg@81 | 273 |
</xsl:if> |
franta-hg@81 | 274 |
} |
franta-hg@80 | 275 |
</p> |
franta-hg@81 | 276 |
[sk8:] |
franta-hg@81 | 277 |
<xsl:if test="not($navázat) and position() = last()"> |
franta-hg@81 | 278 |
→ |
franta-hg@81 | 279 |
<xsl:call-template name="zpracujTělo"> |
franta-hg@81 | 280 |
<xsl:with-param name="prvek" select="$dalšíUzel"/> |
franta-hg@81 | 281 |
<xsl:with-param name="vnořeno" select="false()"/> |
franta-hg@81 | 282 |
</xsl:call-template> |
franta-hg@81 | 283 |
</xsl:if> |
franta-hg@80 | 284 |
</xsl:otherwise> |
franta-hg@80 | 285 |
</xsl:choose> |
franta-hg@79 | 286 |
</xsl:if> |
franta-hg@79 | 287 |
</xsl:for-each> |
franta-hg@79 | 288 |
|
franta-hg@76 | 289 |
</xsl:template> |
franta-hg@77 | 290 |
|
franta-hg@77 | 291 |
|
franta-hg@76 | 292 |
</xsl:stylesheet> |