helpers/mimeTextPart.xsl
author František Kučera <franta-hg@frantovo.cz>
Tue Oct 18 20:54:14 2011 +0200 (2011-10-18)
changeset 96 a0a93e49d055
parent 95 62b9b2533902
child 97 7520a9246ff5
permissions -rw-r--r--
Drupal: text/plain – sjednocení šablony pro ul a ol a odstranění nadbytečných prázdných řádků u vnořených seznamů
     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <xsl:stylesheet version="2.0"
     3 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     4 	xmlns:fn="http://www.w3.org/2005/xpath-functions"
     5 	xmlns:h="http://www.w3.org/1999/xhtml">
     6 	<xsl:output method="text" encoding="UTF-8"/>
     7 	<xsl:strip-space elements="*"/>
     8 	
     9 	<xsl:output method="text" encoding="UTF-8"/>
    10 	<xsl:strip-space elements="*"/>
    11 	
    12 	<xsl:variable name="urlBase" select="/h:html/h:head/h:base/@href"/>
    13 
    14 	
    15 	<!-- Celý dokument -->
    16 	<xsl:template match="/">
    17 		<xsl:apply-templates select="h:html/h:body"/>
    18 	</xsl:template>
    19 
    20 
    21 	<xsl:template match="h:h1">
    22 		<xsl:value-of select="text()"/>
    23 		<xsl:text>&#10;</xsl:text>
    24 		<xsl:for-each select="1 to string-length(.)">=</xsl:for-each>		
    25 		<xsl:text>&#10;</xsl:text>
    26 		<xsl:text>&#10;</xsl:text>
    27 	</xsl:template>
    28 	
    29 	
    30 	<xsl:template match="h:h2">
    31 		<xsl:value-of select="text()"/>
    32 		<xsl:text>&#10;</xsl:text>
    33 		<xsl:for-each select="1 to string-length(.)">-</xsl:for-each>		
    34 		<xsl:text>&#10;</xsl:text>
    35 		<xsl:text>&#10;</xsl:text>
    36 	</xsl:template>
    37 	
    38 	
    39 	<xsl:template match="h:h3">
    40 		<xsl:for-each select="1 to 3">#</xsl:for-each>
    41 		<xsl:text> </xsl:text>
    42 		<xsl:value-of select="text()"/>
    43 		<xsl:text>&#10;</xsl:text>
    44 		<xsl:text>&#10;</xsl:text>
    45 	</xsl:template>
    46 	
    47 	
    48 	<xsl:template match="h:h4">
    49 		<xsl:for-each select="1 to 4">#</xsl:for-each>
    50 		<xsl:text> </xsl:text>
    51 		<xsl:value-of select="text()"/>
    52 		<xsl:text>&#10;</xsl:text>
    53 		<xsl:text>&#10;</xsl:text>
    54 	</xsl:template>
    55 	
    56 	
    57 	<xsl:template match="h:h5">
    58 		<xsl:for-each select="1 to 5">#</xsl:for-each>
    59 		<xsl:text> </xsl:text>
    60 		<xsl:value-of select="text()"/>
    61 		<xsl:text>&#10;</xsl:text>
    62 		<xsl:text>&#10;</xsl:text>
    63 	</xsl:template>
    64 	
    65 	
    66 	<xsl:template match="h:h6">
    67 		<xsl:for-each select="1 to 6">#</xsl:for-each>
    68 		<xsl:text> </xsl:text>
    69 		<xsl:value-of select="text()"/>
    70 		<xsl:text>&#10;</xsl:text>
    71 		<xsl:text>&#10;</xsl:text>
    72 	</xsl:template>
    73 
    74 
    75 	<xsl:template match="h:p">
    76 		<xsl:apply-templates/>
    77 		<xsl:text>&#10;</xsl:text>
    78 		<xsl:text>&#10;</xsl:text>
    79 	</xsl:template>
    80 
    81 	
    82 	<xsl:template match="h:blockquote/h:p">
    83 		<xsl:text>&gt; </xsl:text>
    84 		<xsl:apply-templates/>
    85 		<xsl:text>&#10;</xsl:text>
    86 		<xsl:text>&#10;</xsl:text>
    87 	</xsl:template>
    88 
    89 	<xsl:template match="h:cite[not(matches(., '^(&quot;|„)'))]">
    90 		<xsl:text>„</xsl:text>
    91 		<xsl:apply-templates/>
    92 		<xsl:text>“</xsl:text>
    93 	</xsl:template>	
    94 	
    95 	<xsl:template match="h:a">
    96 		<xsl:text>'</xsl:text>
    97 		<xsl:apply-templates select="node()"/>
    98 		<xsl:text>' &lt;</xsl:text>
    99 		<xsl:choose>
   100 			<xsl:when test="matches(@href, '^(http:|https:|ftp:)')">
   101 				<xsl:value-of select="@href"/>
   102 			</xsl:when>
   103 			<xsl:when test="matches(@href, '^mailto:')">
   104 				<xsl:value-of select="substring-after(@href, 'mailto:')"/>
   105 			</xsl:when>
   106 			<xsl:otherwise>
   107 				<xsl:choose>
   108 					<xsl:when test="ends-with($urlBase, '/') or starts-with(@href, '/')">
   109 						<xsl:value-of select="concat($urlBase, @href)"/>
   110 					</xsl:when>
   111 					<xsl:otherwise>
   112 						<xsl:value-of select="concat($urlBase, '/', @href)"/>
   113 					</xsl:otherwise>
   114 				</xsl:choose>
   115 			</xsl:otherwise>
   116 		</xsl:choose>	
   117 		<xsl:text>&gt;</xsl:text>
   118 		<xsl:if test="@title and not(matches(@title, '^\s*$'))">
   119 			<xsl:text> (</xsl:text>
   120 			<xsl:value-of select="@title"/>
   121 			<xsl:text>)</xsl:text>
   122 		</xsl:if>
   123 	</xsl:template>
   124 	
   125 	
   126 	<xsl:template match="h:img">
   127 		<xsl:variable name="obrázek">
   128 			<h:a href="{@src}" title="{@title}">Obrázek: <xsl:value-of select="@alt"/></h:a>
   129 		</xsl:variable>
   130 		<xsl:apply-templates select="$obrázek/node()"/>
   131 	</xsl:template>
   132 	
   133 	
   134 	<xsl:template match="h:strong|h:b">
   135 		<xsl:text>**</xsl:text>
   136 		<xsl:apply-templates/>
   137 		<xsl:text>**</xsl:text>
   138 	</xsl:template>
   139 	
   140 	
   141 	<xsl:template match="h:em|h:i">
   142 		<xsl:text>*</xsl:text>
   143 		<xsl:apply-templates/>
   144 		<xsl:text>*</xsl:text>
   145 	</xsl:template>
   146 	
   147 	
   148 	<xsl:template match="h:abbr[@title]">
   149 		<xsl:apply-templates/>
   150 		<xsl:text> (</xsl:text>
   151 		<xsl:value-of select="@title"/>
   152 		<xsl:text>)</xsl:text>
   153 	</xsl:template>
   154 	
   155 	
   156 	<xsl:template match="h:pre">
   157 		<xsl:text>--------------------------------</xsl:text>
   158 		<xsl:text>&#10;</xsl:text>
   159 		<xsl:apply-templates/>
   160 		<xsl:text>&#10;</xsl:text>
   161 		<xsl:text>--------------------------------</xsl:text>
   162 		<xsl:text>&#10;</xsl:text>
   163 		<xsl:text>&#10;</xsl:text>
   164 	</xsl:template>
   165 	
   166 	
   167 	<xsl:template match="h:code">
   168 		<xsl:text>`</xsl:text>
   169 		<xsl:apply-templates/>
   170 		<xsl:text>`</xsl:text>
   171 	</xsl:template>
   172 	
   173 	
   174 	<xsl:template match="h:hr">
   175 		<xsl:text>----------------------------------------------------------------</xsl:text>
   176 		<xsl:text>&#10;</xsl:text>
   177 		<xsl:text>&#10;</xsl:text>
   178 	</xsl:template>
   179 	
   180 	
   181 	<xsl:template match="h:ol|h:ul">
   182 		<xsl:variable name="úroveň" select="count(ancestor::h:li)"/>
   183 		<xsl:variable name="odsazení">
   184 			<!-- položky na nejvyšší úrovni odsazené jednou mezerou -->
   185 			<xsl:value-of select="' '"/>
   186 			<xsl:for-each select="2 to $úroveň+1">
   187 				<!-- položky na druhé a vyšší úrovni odsazené vždy dvěma dalšími mezerami -->
   188 				<xsl:value-of select="'  '"/>
   189 			</xsl:for-each>
   190 		</xsl:variable>
   191 		
   192 		<xsl:if test="$úroveň gt 0">
   193 			<xsl:text>&#10;</xsl:text>
   194 		</xsl:if>
   195 		
   196 		<xsl:for-each select="h:li">
   197 			<xsl:if test="parent::h:ol"><xsl:value-of select="concat($odsazení, position(), ') ')"/></xsl:if>
   198 			<xsl:if test="parent::h:ul"><xsl:value-of select="concat($odsazení, '- ')"/></xsl:if>
   199 			<xsl:apply-templates/>
   200 			<xsl:if test="$úroveň = 0 or not(position() = last())">
   201 				<xsl:text>&#10;</xsl:text>
   202 			</xsl:if>
   203 		</xsl:for-each>		
   204 		
   205 		<xsl:if test="$úroveň = 0">
   206 			<xsl:text>&#10;</xsl:text>
   207 		</xsl:if>
   208 	</xsl:template>
   209 	
   210 	
   211 	<xsl:template match="text()[not(parent::h:pre)]">
   212 		<xsl:if test="matches(., '^\s')">
   213 			<xsl:text> </xsl:text>
   214 		</xsl:if>
   215 		<xsl:value-of select="normalize-space(.)"/>
   216 		<xsl:if test="matches(., '\s$')">
   217 			<xsl:text> </xsl:text>
   218 		</xsl:if>
   219 	</xsl:template>
   220 
   221 	
   222 	<xsl:template match="h:div[@class='wwwLinks']">
   223 		<!-- 
   224 			Dvě pomlčky a mezeru budou e-maliloví klienti považovat za začátek podpisu
   225 			a zobrazí ho šedivým písmem a nebudou ho citovat v odpovědích.
   226 		-->
   227 		<xsl:text>-- </xsl:text>
   228 		<xsl:text>&#10;</xsl:text>
   229 		<xsl:apply-templates/>	
   230 	</xsl:template>	
   231 
   232 
   233 </xsl:stylesheet>