author | František Kučera <franta-hg@frantovo.cz> |
Fri, 14 Oct 2011 12:41:14 +0200 | |
changeset 77 | 623025c704c5 |
parent 76 | b5690fc25af6 |
child 78 | 969f001a0f5f |
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@77 | 75 |
} |
franta-hg@76 | 76 |
</style> |
franta-hg@76 | 77 |
</head> |
franta-hg@76 | 78 |
<body> |
franta-hg@76 | 79 |
<xsl:if test="$title and $isRoot"> |
franta-hg@76 | 80 |
<h1><xsl:value-of select="$title"/></h1> |
franta-hg@76 | 81 |
</xsl:if> |
franta-hg@76 | 82 |
<xsl:apply-templates select="h:html/h:body/node()"/> |
franta-hg@76 | 83 |
|
franta-hg@76 | 84 |
<xsl:if test="$wwwRead or $wwwPost"> |
franta-hg@76 | 85 |
<div class="wwwLinks"> |
franta-hg@76 | 86 |
<p>Přístup přes síť www:</p> |
franta-hg@76 | 87 |
<ul> |
franta-hg@76 | 88 |
<xsl:if test="$wwwRead"><li><a href="{$wwwRead}">číst tento příspěvek</a></li></xsl:if> |
franta-hg@76 | 89 |
<xsl:if test="$wwwPost"><li><a href="{$wwwPost}">odpovědět na tento příspěvek</a></li></xsl:if> |
franta-hg@76 | 90 |
</ul> |
franta-hg@76 | 91 |
</div> |
franta-hg@76 | 92 |
</xsl:if> |
franta-hg@76 | 93 |
</body> |
franta-hg@76 | 94 |
</html> |
franta-hg@76 | 95 |
</xsl:template> |
franta-hg@76 | 96 |
|
franta-hg@76 | 97 |
|
franta-hg@76 | 98 |
<!-- Odkazy --> |
franta-hg@76 | 99 |
<xsl:template match="h:a"> |
franta-hg@76 | 100 |
<a href="{@href}" title="{@title}"><xsl:apply-templates/></a> |
franta-hg@76 | 101 |
</xsl:template> |
franta-hg@76 | 102 |
|
franta-hg@76 | 103 |
|
franta-hg@76 | 104 |
<!-- Obrázky --> |
franta-hg@76 | 105 |
<xsl:template match="h:img"> |
franta-hg@76 | 106 |
<img src="{@src}" alt="{@alt}" title="{@title}"><xsl:apply-templates/></img> |
franta-hg@76 | 107 |
</xsl:template> |
franta-hg@76 | 108 |
|
franta-hg@76 | 109 |
<!-- Zkratky --> |
franta-hg@76 | 110 |
<xsl:template match="h:abbr"> |
franta-hg@76 | 111 |
<abbr title="{@title}"><xsl:apply-templates/></abbr> |
franta-hg@76 | 112 |
</xsl:template> |
franta-hg@76 | 113 |
|
franta-hg@76 | 114 |
|
franta-hg@76 | 115 |
<!-- Další povolené značky – ostatní odfiltrujeme (zbude z nich jen text) --> |
franta-hg@76 | 116 |
<xsl:template match="*"> |
franta-hg@76 | 117 |
<xsl:choose> |
franta-hg@76 | 118 |
<xsl:when test=" |
franta-hg@76 | 119 |
name() = 'h1' or |
franta-hg@76 | 120 |
name() = 'h2' or |
franta-hg@76 | 121 |
name() = 'h3' or |
franta-hg@76 | 122 |
name() = 'h4' or |
franta-hg@76 | 123 |
name() = 'h5' or |
franta-hg@76 | 124 |
name() = 'h6' or |
franta-hg@76 | 125 |
name() = 'p' or |
franta-hg@76 | 126 |
name() = 'div' or |
franta-hg@76 | 127 |
name() = 'br' or |
franta-hg@76 | 128 |
name() = 'strong' or |
franta-hg@76 | 129 |
name() = 'em' or |
franta-hg@76 | 130 |
name() = 'sub' or |
franta-hg@76 | 131 |
name() = 'sup' or |
franta-hg@76 | 132 |
name() = 'del' or |
franta-hg@76 | 133 |
name() = 'ul' or |
franta-hg@76 | 134 |
name() = 'ol' or |
franta-hg@76 | 135 |
name() = 'li' or |
franta-hg@76 | 136 |
name() = 'pre' or |
franta-hg@76 | 137 |
name() = 'code' or |
franta-hg@76 | 138 |
name() = 'blockquote'"> |
franta-hg@76 | 139 |
<xsl:element name="{name()}"> |
franta-hg@76 | 140 |
<xsl:apply-templates/> |
franta-hg@76 | 141 |
</xsl:element> |
franta-hg@76 | 142 |
</xsl:when> |
franta-hg@76 | 143 |
<xsl:otherwise> |
franta-hg@76 | 144 |
<xsl:value-of select="."/> |
franta-hg@76 | 145 |
</xsl:otherwise> |
franta-hg@76 | 146 |
</xsl:choose> |
franta-hg@76 | 147 |
</xsl:template> |
franta-hg@76 | 148 |
|
franta-hg@76 | 149 |
|
franta-hg@76 | 150 |
<!-- |
franta-hg@76 | 151 |
Z neuzavřeného (nevalidně se vyskytujícího v body) textu uděláme odstavce. |
franta-hg@76 | 152 |
--> |
franta-hg@76 | 153 |
<xsl:template match="h:body/text()"> |
franta-hg@77 | 154 |
<xsl:call-template name="dělejOdstavce"> |
franta-hg@77 | 155 |
<xsl:with-param name="blokTextu" select="."/> |
franta-hg@77 | 156 |
</xsl:call-template> |
franta-hg@76 | 157 |
</xsl:template> |
franta-hg@77 | 158 |
<xsl:template name="dělejOdstavce"> |
franta-hg@77 | 159 |
<xsl:param name="blokTextu"/> |
franta-hg@77 | 160 |
<xsl:variable name="oddělovač" select="'\n\s+\n\s+'"/> |
franta-hg@77 | 161 |
<xsl:for-each select="fn:tokenize(., $oddělovač)"> |
franta-hg@77 | 162 |
<xsl:if test="normalize-space(.)"> |
franta-hg@77 | 163 |
<p class="mešuge"> |
franta-hg@77 | 164 |
<xsl:value-of select="."/> |
franta-hg@77 | 165 |
<!-- |
franta-hg@77 | 166 |
Toto je poslední odstavec bloku textu |
franta-hg@77 | 167 |
a blok nekončí dvěma konci řádku → |
franta-hg@77 | 168 |
může za ním následovat značka (např. odkaz nebo tučné písmo) |
franta-hg@77 | 169 |
vnořená do téhož odstavce |
franta-hg@77 | 170 |
--> |
franta-hg@77 | 171 |
<xsl:if test=" |
franta-hg@77 | 172 |
position() = last() and |
franta-hg@77 | 173 |
not(fn:matches($blokTextu, concat('.*', $oddělovač ,'$'))) |
franta-hg@77 | 174 |
"> |
franta-hg@77 | 175 |
|
franta-hg@77 | 176 |
<xsl:variable name="n" select="$blokTextu/following-sibling::*[position() = 1]"/> |
franta-hg@77 | 177 |
<xsl:variable name="nn" select="$n/name()"/> |
franta-hg@77 | 178 |
<!-- |
franta-hg@77 | 179 |
Za blokem textu nenásleduje značka, která nemůže být uvnitř odstavce. |
franta-hg@77 | 180 |
--> |
franta-hg@77 | 181 |
<xsl:if test="not( |
franta-hg@77 | 182 |
$nn = 'p' or |
franta-hg@77 | 183 |
$nn = 'div' or |
franta-hg@77 | 184 |
$nn = 'h1' or |
franta-hg@77 | 185 |
$nn = 'h2' or |
franta-hg@77 | 186 |
$nn = 'h3' or |
franta-hg@77 | 187 |
$nn = 'h4' or |
franta-hg@77 | 188 |
$nn = 'h5' or |
franta-hg@77 | 189 |
$nn = 'h6' or |
franta-hg@77 | 190 |
$nn = 'pre' or |
franta-hg@77 | 191 |
$nn = 'table' or |
franta-hg@77 | 192 |
$nn = 'blockquote' or |
franta-hg@77 | 193 |
$nn = 'hr' |
franta-hg@77 | 194 |
)"> |
franta-hg@77 | 195 |
<xsl:apply-templates select="$n"/> |
franta-hg@77 | 196 |
<xsl:apply-templates select="$n/following-sibling::text()[position() = 1]"/> |
franta-hg@77 | 197 |
</xsl:if> |
franta-hg@77 | 198 |
</xsl:if> |
franta-hg@77 | 199 |
</p> |
franta-hg@77 | 200 |
</xsl:if> |
franta-hg@77 | 201 |
</xsl:for-each> |
franta-hg@76 | 202 |
</xsl:template> |
franta-hg@77 | 203 |
|
franta-hg@77 | 204 |
|
franta-hg@76 | 205 |
</xsl:stylesheet> |