helpers/mimeTextPart.xsl
author František Kučera <franta-hg@frantovo.cz>
Mon Oct 17 18:14:34 2011 +0200 (2011-10-17)
changeset 89 c60625d58158
child 90 2ed2497d4559
permissions -rw-r--r--
Drupal: textová část zpráv (text/plain), základní funkční verze (XSLT+Java).
     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 	<!-- Celý dokument -->
    15 	<xsl:template match="/">
    16 		<xsl:apply-templates select="h:html/h:body"/>
    17 	</xsl:template>
    18 
    19 	<xsl:template match="h:h1">
    20 		<xsl:value-of select="text()"/>
    21 		<xsl:text>&#10;</xsl:text>
    22 		<xsl:for-each select="1 to string-length(.)">#</xsl:for-each>		
    23 		<xsl:text>&#10;</xsl:text>
    24 		<xsl:text>&#10;</xsl:text>
    25 	</xsl:template>
    26 	
    27 	<xsl:template match="h:h2">
    28 		<xsl:value-of select="text()"/>
    29 		<xsl:text>&#10;</xsl:text>
    30 		<xsl:for-each select="1 to string-length(.)">-</xsl:for-each>		
    31 		<xsl:text>&#10;</xsl:text>
    32 		<xsl:text>&#10;</xsl:text>
    33 	</xsl:template>
    34 	
    35 	<xsl:template match="h:h3">
    36 		<xsl:for-each select="1 to 3">#</xsl:for-each>
    37 		<xsl:text> </xsl:text>
    38 		<xsl:value-of select="text()"/>
    39 		<xsl:text>&#10;</xsl:text>
    40 		<xsl:text>&#10;</xsl:text>
    41 	</xsl:template>
    42 
    43 	
    44 	<xsl:template match="h:h4">
    45 		<xsl:for-each select="1 to 4">#</xsl:for-each>
    46 		<xsl:text> </xsl:text>
    47 		<xsl:value-of select="text()"/>
    48 		<xsl:text>&#10;</xsl:text>
    49 		<xsl:text>&#10;</xsl:text>
    50 	</xsl:template>
    51 
    52 	
    53 	<xsl:template match="h:h5">
    54 		<xsl:for-each select="1 to 5">#</xsl:for-each>
    55 		<xsl:text> </xsl:text>
    56 		<xsl:value-of select="text()"/>
    57 		<xsl:text>&#10;</xsl:text>
    58 		<xsl:text>&#10;</xsl:text>
    59 	</xsl:template>
    60 	
    61 	<xsl:template match="h:h6">
    62 		<xsl:for-each select="1 to 6">#</xsl:for-each>
    63 		<xsl:text> </xsl:text>
    64 		<xsl:value-of select="text()"/>
    65 		<xsl:text>&#10;</xsl:text>
    66 		<xsl:text>&#10;</xsl:text>
    67 	</xsl:template>
    68 
    69 
    70 	<xsl:template match="h:p">
    71 		<xsl:apply-templates/>
    72 		<xsl:text>&#10;</xsl:text>
    73 		<xsl:text>&#10;</xsl:text>
    74 	</xsl:template>
    75 	
    76 	<xsl:template match="h:a">
    77 		<xsl:text>"</xsl:text>
    78 		<xsl:value-of select="text()"/>
    79 		<xsl:text>" &lt;</xsl:text>
    80 		<xsl:choose>
    81 			<xsl:when test="matches(@href, '^(http:|https:|ftp:)')">
    82 				<xsl:value-of select="@href"/>
    83 			</xsl:when>
    84 			<xsl:when test="matches(@href, '^mailto:')">
    85 				<xsl:value-of select="substring-after(@href, 'mailto:')"/>
    86 			</xsl:when>
    87 			<xsl:otherwise>
    88 				<xsl:choose>
    89 					<xsl:when test="ends-with($urlBase, '/') or starts-with(@href, '/')">
    90 						<xsl:value-of select="concat($urlBase, @href)"/>
    91 					</xsl:when>
    92 					<xsl:otherwise>
    93 						<xsl:value-of select="concat($urlBase, '/', @href)"/>
    94 					</xsl:otherwise>
    95 				</xsl:choose>
    96 			</xsl:otherwise>
    97 		</xsl:choose>	
    98 		<xsl:text>&gt;</xsl:text>
    99 		<xsl:if test="@title and not(matches(@title, '^\s*$'))">
   100 			<xsl:text> (</xsl:text>
   101 			<xsl:value-of select="@title"/>
   102 			<xsl:text>)</xsl:text>
   103 		</xsl:if>
   104 	</xsl:template>
   105 	
   106 	<xsl:template match="h:img">
   107 		<xsl:variable name="obrázek">
   108 			<h:a href="{@src}" title="{@title}">Obrázek: <xsl:value-of select="@alt"/></h:a>
   109 		</xsl:variable>
   110 		<xsl:apply-templates select="$obrázek/node()"/>
   111 	</xsl:template>
   112 	
   113 	<xsl:template match="h:strong|h:b">
   114 		<xsl:text>**</xsl:text>
   115 		<xsl:apply-templates/>
   116 		<xsl:text>**</xsl:text>
   117 	</xsl:template>
   118 	
   119 	<xsl:template match="h:em|h:i">
   120 		<xsl:text>*</xsl:text>
   121 		<xsl:apply-templates/>
   122 		<xsl:text>*</xsl:text>
   123 	</xsl:template>
   124 	
   125 	<xsl:template match="h:abbr[@title]">
   126 		<xsl:apply-templates/>
   127 		<xsl:text> (</xsl:text>
   128 		<xsl:value-of select="@title"/>
   129 		<xsl:text>)</xsl:text>
   130 	</xsl:template>
   131 	
   132 	<xsl:template match="h:pre">
   133 		<xsl:text>--------------------------------</xsl:text>
   134 		<xsl:text>&#10;</xsl:text>
   135 		<xsl:apply-templates/>
   136 		<xsl:text>&#10;</xsl:text>
   137 		<xsl:text>--------------------------------</xsl:text>
   138 		<xsl:text>&#10;</xsl:text>
   139 		<xsl:text>&#10;</xsl:text>
   140 	</xsl:template>
   141 	
   142 	<xsl:template match="h:code">
   143 		<xsl:text>`</xsl:text>
   144 		<xsl:apply-templates/>
   145 		<xsl:text>`</xsl:text>
   146 	</xsl:template>
   147 	
   148 	<xsl:template match="h:hr">
   149 		<xsl:text>----------------------------------------------------------------</xsl:text>
   150 		<xsl:text>&#10;</xsl:text>
   151 		<xsl:text>&#10;</xsl:text>
   152 	</xsl:template>
   153 	
   154 	<xsl:template match="h:ul">
   155 		<xsl:apply-templates/>
   156 		<xsl:text>&#10;</xsl:text>
   157 	</xsl:template>
   158 	
   159 	<xsl:template match="h:ul/h:li">
   160 		<xsl:text> - </xsl:text>
   161 		<xsl:apply-templates/>
   162 		<xsl:text>&#10;</xsl:text>
   163 	</xsl:template>
   164 	
   165 	<xsl:template match="h:ol">
   166 		<xsl:for-each select="h:li">
   167 			<xsl:value-of select="concat(' ', position(), ') ')"/>
   168 			<xsl:apply-templates/>
   169 			<xsl:text>&#10;</xsl:text>
   170 		</xsl:for-each>		
   171 		<xsl:text>&#10;</xsl:text>
   172 	</xsl:template>
   173 	
   174 	
   175 	<!--
   176 	<xsl:template match="h:blockquote[matches(p/text(), '^(\"|„)')]">
   177 		
   178 	</xsl:template>
   179 	-->
   180 	
   181 	<xsl:template match="text()[not(parent::h:pre)]">
   182 		<xsl:if test="matches(., '^\s')">
   183 			<xsl:text> </xsl:text>
   184 		</xsl:if>
   185 		<xsl:value-of select="normalize-space(.)"/>
   186 		<xsl:if test="matches(., '\s$')">
   187 			<xsl:text> </xsl:text>
   188 		</xsl:if>
   189 	</xsl:template>
   190 
   191 	
   192 	<xsl:template match="h:div[@class='wwwLinks']">
   193 		<xsl:text>-- </xsl:text>
   194 		<xsl:text>&#10;</xsl:text>
   195 		<xsl:apply-templates/>	
   196 	</xsl:template>	
   197 
   198 
   199 </xsl:stylesheet>