helpers/mimeXhtmlPart.xsl
changeset 83 668014315a54
parent 81 b51ab80c7a9d
child 85 a76b94bcec92
     1.1 --- a/helpers/mimeXhtmlPart.xsl	Sun Oct 16 20:55:46 2011 +0200
     1.2 +++ b/helpers/mimeXhtmlPart.xsl	Sun Oct 16 23:41:04 2011 +0200
     1.3 @@ -16,6 +16,7 @@
     1.4  	
     1.5  		
     1.6  	<xsl:param name="title"/>
     1.7 +	<xsl:param name="headComment"/>
     1.8  	<xsl:param name="isRoot"/>
     1.9  	<xsl:param name="urlBase"/>
    1.10  	<xsl:param name="wwwRead"/>
    1.11 @@ -27,13 +28,15 @@
    1.12  		<html>
    1.13  			<head>
    1.14  				<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
    1.15 -				<meta http-equiv="X-NNTP-Generated" content="{fn:current-dateTime()}" />
    1.16  				<xsl:if test="$urlBase">
    1.17  					<base href="{$urlBase}"/>
    1.18  				</xsl:if>
    1.19  				<xsl:if test="$title">
    1.20  					<title><xsl:value-of select="$title"/></title>
    1.21  				</xsl:if>
    1.22 +				<xsl:if test="$headComment">
    1.23 +					<xsl:comment><xsl:value-of select="$headComment"/></xsl:comment>
    1.24 +				</xsl:if>
    1.25  				<style type="text/css">
    1.26  					body {
    1.27  						font-family: sans-serif;
    1.28 @@ -68,21 +71,14 @@
    1.29  					a img {
    1.30  						border: none;
    1.31  					}
    1.32 -					
    1.33 -					/** TODO: smazat */
    1.34 -					.mešuge {
    1.35 -						background-color: #afa;
    1.36 -						border: 1px solid #55f;
    1.37 -					}
    1.38  				</style>
    1.39  			</head>
    1.40  			<body>
    1.41  				<xsl:if test="$title and $isRoot">
    1.42  					<h1><xsl:value-of select="$title"/></h1>			
    1.43  				</xsl:if>
    1.44 -				<xsl:call-template name="zpracujTělo">
    1.45 -					<xsl:with-param name="prvek" select="h:html/h:body/node()[1]"/>
    1.46 -				</xsl:call-template>
    1.47 +								
    1.48 +				<xsl:apply-templates select="h:html/h:body"/>
    1.49  				
    1.50  				<xsl:if test="$wwwRead or $wwwPost">
    1.51  					<div class="wwwLinks">
    1.52 @@ -140,153 +136,13 @@
    1.53  				name() = 'code' or
    1.54  				name() = 'blockquote'">
    1.55  				<xsl:element name="{name()}">
    1.56 -					<xsl:apply-templates/>
    1.57 +					<xsl:copy-of select="."/>
    1.58  				</xsl:element>
    1.59  			</xsl:when>
    1.60  			<xsl:otherwise>
    1.61 -				<xsl:value-of select="."/>
    1.62 +				<xsl:apply-templates/>
    1.63  			</xsl:otherwise>
    1.64  		</xsl:choose>		
    1.65      </xsl:template>
    1.66 -    
    1.67 -    <!-- 
    1.68 -    	Z neuzavřeného (nevalidně se vyskytujícího v body) textu uděláme odstavce.
    1.69 -    -->
    1.70 -	<xsl:template name="zpracujTělo">
    1.71 -		<xsl:param name="prvek"/>
    1.72 -		<xsl:param name="vnořeno" select="false()"/>
    1.73 -		<xsl:if test="$prvek">
    1.74 -			<xsl:choose>
    1.75 -				<xsl:when test="$prvek/self::text()">
    1.76 -					<!--
    1.77 -						Textový uzel → budeme dělat odstavce
    1.78 -						(rekurzivně se opět zavolá šablona zpracujTělo)
    1.79 -					-->
    1.80 -					<xsl:call-template name="dělejOdstavce">
    1.81 -						<xsl:with-param name="blokTextu" select="$prvek"/>
    1.82 -						<xsl:with-param name="vnořeno" select="$vnořeno"/>
    1.83 -					</xsl:call-template>
    1.84 -					
    1.85 -					<!-- 
    1.86 -					<xsl:variable name="navázat" as="xs:boolean">
    1.87 -						<xsl:call-template name="navázat">
    1.88 -							<xsl:with-param name="blokTextu" select="$prvek"/>
    1.89 -						</xsl:call-template>
    1.90 -					</xsl:variable>
    1.91 -					
    1.92 -					Někdy zpracujTělo dalšího prvku 
    1.93 -					<xsl:if test="not($navázat)">[další:]
    1.94 -						<xsl:call-template name="zpracujTělo">
    1.95 -							<xsl:with-param name="prvek" select="$prvek/following-sibling::node()[1]"/>
    1.96 -							<xsl:with-param name="vnořeno" select="$vnořeno"/>
    1.97 -						</xsl:call-template>
    1.98 -					</xsl:if>
    1.99 -					-->
   1.100 -					
   1.101 -				</xsl:when>
   1.102 -				<xsl:otherwise>
   1.103 -					<!--
   1.104 -						Jiný uzel → aplikujeme obecné šablony
   1.105 -						a zpracujeme následující uzel.
   1.106 -					-->
   1.107 -					<xsl:apply-templates select="$prvek"/>
   1.108 -					<xsl:call-template name="zpracujTělo">
   1.109 -						<xsl:with-param name="prvek" select="$prvek/following-sibling::node()[1]"/>
   1.110 -						<xsl:with-param name="vnořeno" select="$vnořeno"/>
   1.111 -					</xsl:call-template>
   1.112 -				</xsl:otherwise>					
   1.113 -			</xsl:choose>				
   1.114 -		</xsl:if>
   1.115 -	</xsl:template>
   1.116 -	
   1.117 -	<xsl:variable name="oddělovač" select="'\n\s*\n\s*'"/>
   1.118 -	
   1.119 -	<xsl:template name="navázat" as="xs:boolean">
   1.120 -		<xsl:param name="blokTextu"/>
   1.121 -		<xsl:variable name="dalšíUzel" select="$blokTextu/following-sibling::node()[1]"/>
   1.122 -		<xsl:sequence select="
   1.123 -			not(fn:matches($blokTextu, concat('.*', $oddělovač ,'$'))) and
   1.124 -			$dalšíUzel and
   1.125 -			not(
   1.126 -				$dalšíUzel/name() = 'p' or
   1.127 -				$dalšíUzel/name() = 'div' or								
   1.128 -				$dalšíUzel/name() = 'h1' or								
   1.129 -				$dalšíUzel/name() = 'h2' or								
   1.130 -				$dalšíUzel/name() = 'h3' or								
   1.131 -				$dalšíUzel/name() = 'h4' or								
   1.132 -				$dalšíUzel/name() = 'h5' or								
   1.133 -				$dalšíUzel/name() = 'h6' or								
   1.134 -				$dalšíUzel/name() = 'pre' or								
   1.135 -				$dalšíUzel/name() = 'table' or								
   1.136 -				$dalšíUzel/name() = 'blockquote' or								
   1.137 -				$dalšíUzel/name() = 'hr'								
   1.138 -			)
   1.139 -		"/>
   1.140 -	</xsl:template>
   1.141 -	
   1.142 -	<xsl:template name="dělejOdstavce">
   1.143 -		<xsl:param name="blokTextu"/>
   1.144 -		<xsl:param name="vnořeno" select="false()"/>
   1.145 -		
   1.146 -		<xsl:variable name="dalšíUzel" select="$blokTextu/following-sibling::node()[1]"/>
   1.147 -		
   1.148 -		<xsl:variable name="navázat" as="xs:boolean">
   1.149 -			<xsl:call-template name="navázat">
   1.150 -				<xsl:with-param name="blokTextu" select="$blokTextu"/>
   1.151 -			</xsl:call-template>
   1.152 -		</xsl:variable>
   1.153 -		
   1.154 -		<xsl:for-each select="fn:tokenize($blokTextu, $oddělovač)">
   1.155 -			<!-- TODO: ošetřit prázdné odstavce -->
   1.156 -			<xsl:if test="normalize-space(.) or true()">
   1.157 -				<xsl:choose>
   1.158 -					<xsl:when test="$vnořeno">
   1.159 -						[
   1.160 -							<xsl:value-of select="."/>
   1.161 -							<xsl:if test="$navázat and position() = last()">
   1.162 -								→
   1.163 -								<xsl:call-template name="zpracujTělo">
   1.164 -									<xsl:with-param name="prvek" select="$dalšíUzel"/>
   1.165 -									<xsl:with-param name="vnořeno" select="true()"/>
   1.166 -								</xsl:call-template>
   1.167 -							</xsl:if>
   1.168 -						]
   1.169 -						[Avril:]
   1.170 -						<xsl:if test="not($navázat) and position() = last()">
   1.171 -							a→
   1.172 -								<xsl:call-template name="zpracujTělo">
   1.173 -									<xsl:with-param name="prvek" select="$dalšíUzel"/>
   1.174 -									<xsl:with-param name="vnořeno" select="true()"/>
   1.175 -								</xsl:call-template>
   1.176 -						</xsl:if>
   1.177 -					</xsl:when>
   1.178 -					<xsl:otherwise>
   1.179 -						<p class="mešuge">
   1.180 -						{
   1.181 -							<xsl:value-of select="."/>
   1.182 -							<xsl:if test="$navázat and position() = last()">
   1.183 -								s→
   1.184 -								<xsl:call-template name="zpracujTělo">
   1.185 -									<xsl:with-param name="prvek" select="$dalšíUzel"/>
   1.186 -									<xsl:with-param name="vnořeno" select="true()"/>
   1.187 -								</xsl:call-template>
   1.188 -							</xsl:if>
   1.189 -						}
   1.190 -						</p>
   1.191 -						[sk8:]
   1.192 -						<xsl:if test="not($navázat) and position() = last()">
   1.193 -							→
   1.194 -								<xsl:call-template name="zpracujTělo">
   1.195 -									<xsl:with-param name="prvek" select="$dalšíUzel"/>
   1.196 -									<xsl:with-param name="vnořeno" select="false()"/>
   1.197 -								</xsl:call-template>
   1.198 -						</xsl:if>
   1.199 -					</xsl:otherwise>
   1.200 -				</xsl:choose>
   1.201 -			</xsl:if>
   1.202 -		</xsl:for-each>
   1.203 -		
   1.204 -	</xsl:template>
   1.205 -    
   1.206  	
   1.207  </xsl:stylesheet>