šablona/makra/odkazy.xsl
author František Kučera <franta-hg@frantovo.cz>
Sat, 23 Jun 2012 20:40:18 +0200
changeset 98 532deb4b908e
parent 93 5b55827de220
child 136 d5feb9d8ebc3
permissions -rw-r--r--
drobnosti
     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <!--
     3 XML Web generátor – program na generování webových stránek
     4 Copyright © 2012 František Kučera (frantovo.cz)
     5 
     6 This program is free software: you can redistribute it and/or modify
     7 it under the terms of the GNU General Public License as published by
     8 the Free Software Foundation, either version 3 of the License, or
     9 (at your option) any later version.
    10 
    11 This program is distributed in the hope that it will be useful,
    12 but WITHOUT ANY WARRANTY; without even the implied warranty of
    13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14 GNU General Public License for more details.
    15 
    16 You should have received a copy of the GNU General Public License
    17 along with this program.  If not, see <http://www.gnu.org/licenses/>.
    18 -->
    19 <xsl:stylesheet version="2.0"
    20 	xmlns="http://www.w3.org/1999/xhtml"
    21 	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"
    22 	xmlns:k="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/konfigurace"
    23 	xmlns:xs="http://www.w3.org/2001/XMLSchema"
    24 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    25 	exclude-result-prefixes="m k xs">
    26 
    27 	<!--
    28 		Interní odkazy
    29 		**************
    30 		Slouží k vkládání odkazů na jiné stránky v rámci webu.
    31 		*
    32 		@href zadáváme jen název souboru bez přípony – s nezakódovanou češtinou a s mezerami
    33 		@typ nevyplňujeme
    34 	-->
    35 	<xsl:template match="m:a[not(@typ)]">
    36 		<a>
    37 			<xsl:copy-of select="@*"/>
    38 			<xsl:attribute name="href">
    39 				<xsl:value-of select="encode-for-uri(concat(@href, $výstupníPřípona))"/>
    40 			</xsl:attribute>
    41 			<xsl:apply-templates/>
    42 		</a>
    43 	</xsl:template>
    44 
    45 	<xsl:variable name="tracURL" select="'https://trac.frantovo.cz/xml-web-generator'"/>
    46 
    47 	<!--
    48 		Trac – wiki
    49 		***********
    50 		Odkazy na Trac našeho generátoru.
    51 		*
    52 		@href nečíselné parametry vedou do wiki
    53 	-->
    54 	<xsl:template match="m:a[@typ='trac' and not(number(@href))]">
    55 		<xsl:call-template name="vložOdkaz">
    56 			<xsl:with-param name="url" select="
    57 				concat(
    58 					$tracURL, '/wiki/', 
    59 					m:escapuj-url-zachovej-lomítka(@href)
    60 				)"/>
    61 		</xsl:call-template>		
    62 	</xsl:template>
    63 
    64 	<!--
    65 		Trac – úkoly
    66 		************
    67 		Odkazy na Trac našeho generátoru.
    68 		*
    69 		@href číselné parametry vedou na úkoly
    70 	-->
    71 	<xsl:template match="m:a[@typ='trac' and number(@href)]">
    72 		<xsl:call-template name="vložOdkaz">
    73 			<xsl:with-param name="url" select="
    74 				concat(
    75 					$tracURL, '/ticket/', 
    76 					@href
    77 				)"/>
    78 		</xsl:call-template>
    79 	</xsl:template>
    80 
    81 	<!--
    82 		Zdroják
    83 		*******
    84 		Odkazy zdrojový kód našeho generátoru.
    85 		*
    86 		@href název souboru
    87 		@řádek číslo řádku (volitelně)
    88 	-->
    89 	<xsl:template match="m:a[@typ='zdroják' and (not(@řádek) or number(@řádek))]">
    90 		<xsl:call-template name="vložOdkaz">
    91 			<xsl:with-param name="url" select="
    92 				concat(
    93 					$tracURL, '/browser/', 
    94 					m:escapuj-url-zachovej-lomítka(@href),
    95 					'#L',
    96 					(@řádek,'1')[1]
    97 				)"/>
    98 		</xsl:call-template>
    99 	</xsl:template>
   100 
   101 	<!--
   102 		Wikipedia
   103 		*********
   104 		Stránka v encyklopedii.
   105 		*
   106 		@href název stránky
   107 		@jazyk kód jazyka (výchozí je čeština)
   108 	-->
   109 	<xsl:template match="m:a[@typ='wiki']">
   110 		<xsl:call-template name="vložOdkaz">
   111 			<xsl:with-param name="url" select="
   112 				concat(
   113 					'https://secure.wikimedia.org/wikipedia/', (@jazyk,'cs')[1], '/wiki/', 
   114 					m:escapuj-url-zachovej-lomítka(@href)
   115 				)"/>
   116 		</xsl:call-template>
   117 	</xsl:template>
   118 
   119 	<!--
   120 		Javadoc
   121 		*******
   122 		Dokumentace k javovským třídám.
   123 		*
   124 		@href jméno třídy včetně balíčku – např. java.lang.String
   125 		@verze verze Javy, výchozí: 7
   126 	-->
   127 	<xsl:template match="m:a[@typ='javadoc']">
   128 		<xsl:call-template name="vložOdkaz">
   129 			<xsl:with-param name="url" select="
   130 				concat(
   131 					'http://docs.oracle.com/javase/', (@verze,'7')[1], '/docs/api/',
   132 					replace(@href, '\.', '/'),
   133 					'.html'
   134 				)"/>
   135 		</xsl:call-template>
   136 	</xsl:template>
   137 
   138 	<!-- 
   139 		Seznam.cz
   140 		*********
   141 		Vyhledávání pomocí Seznamu.
   142 		*
   143 		@href náš dotaz
   144 	-->
   145 	<xsl:template match="m:a[@typ='seznam']">
   146 		<xsl:call-template name="vložOdkaz">
   147 			<xsl:with-param name="url" select="
   148 				concat(
   149 					'http://search.seznam.cz/?q=', 
   150 					encode-for-uri(@href)
   151 				)"/>
   152 		</xsl:call-template>
   153 	</xsl:template>
   154 
   155 	<!-- 
   156 		Google.com
   157 		**********
   158 		Vyhledávání pomocí Googlu.
   159 		*
   160 		@href náš dotaz
   161 	-->
   162 	<xsl:template match="m:a[@typ='google']">
   163 		<xsl:call-template name="vložOdkaz">
   164 			<xsl:with-param name="url" select="
   165 				concat(
   166 					'https://encrypted.google.com/search?q=', 
   167 					encode-for-uri(@href)
   168 				)"/>
   169 		</xsl:call-template>	
   170 	</xsl:template>
   171 
   172 	<!-- 
   173 		Request for comments
   174 		********************
   175 		Internetové standardy – RFC.
   176 		*
   177 		@href číslo RFCčka
   178 	-->
   179 	<xsl:template match="m:a[@typ='rfc' and number(@href)]">
   180 		<xsl:call-template name="vložOdkaz">
   181 			<xsl:with-param name="url" select="
   182 				concat(
   183 					'https://tools.ietf.org/html/rfc',
   184 					@href
   185 				)"/>
   186 		</xsl:call-template>
   187 	</xsl:template>
   188 
   189 	<!--
   190 		E-mail
   191 		******
   192 		Odkaz na e-mail v „obfuskovaném“ tvaru,
   193 		aby spamovací roboti nemohli tak snadno sbírat e-mailové adresy z webů.
   194 		Ale zároveň klikatelný, aby ho uživatel nemusel opisovat (vyžaduje JavaScript).
   195 		Obsah elementu je nepovinný – pokud chybí, vloží se e-mailová adresa.
   196 		*
   197 		@href e-mailová adresa (bez „mailto:“)
   198 	-->
   199 	<xsl:template match="m:a[@typ='email']">
   200 		<xsl:variable name="česky" select="replace(replace(@href, '@', ' zavináč '), '\.', ' tečka ')"/>
   201 		<xsl:variable name="klíč" select="concat(tokenize($konfigurace/k:web/k:uuid/text(), '-')[1], '9df1')"/>
   202 		<xsl:variable name="pořadí"><xsl:number level="any"/></xsl:variable>
   203 		<xsl:variable name="idSpanu" select="concat('c', $klíč, $pořadí)"/>
   204 		<span title="{text()}" id="{$idSpanu}">
   205 			<xsl:value-of select="$česky"/>
   206 		</span>
   207 		<span id="{$idSpanu}b" style="display: none">
   208 			<xsl:apply-templates/>
   209 		</span>
   210 		<script type="text/javascript">
   211 			xwg.odkazNaElektronickouPoštu("<xsl:value-of select="$idSpanu"/>");
   212 		</script>
   213 	</xsl:template>
   214 
   215 
   216 	<xsl:template name="vložOdkaz">
   217 		<xsl:param name="url"/>
   218 		<a>
   219 			<!-- Zachováme pouze povolené atributy: -->
   220 			
   221 			<xsl:copy-of select="@charset"/>
   222 			<xsl:copy-of select="@coords"/>
   223 			<xsl:copy-of select="@hreflang"/>
   224 			<xsl:copy-of select="@name"/>
   225 			<xsl:copy-of select="@rel"/>
   226 			<xsl:copy-of select="@rev"/>
   227 			<xsl:copy-of select="@shape"/>
   228 			<xsl:copy-of select="@target"/> <!-- Pozor: nepatří do striktního XHTML -->
   229 			
   230 			<xsl:copy-of select="@accesskey"/>
   231 			<xsl:copy-of select="@class"/>
   232 			<xsl:copy-of select="@dir"/>
   233 			<xsl:copy-of select="@id"/>
   234 			<xsl:copy-of select="@lang"/>
   235 			<xsl:copy-of select="@style"/>
   236 			<xsl:copy-of select="@tabindex"/>
   237 			<xsl:copy-of select="@title"/>
   238 			<xsl:copy-of select="@xml:lang"/>
   239 			
   240 			<xsl:copy-of select="@onblur"/>
   241 			<xsl:copy-of select="@onclick"/>
   242 			<xsl:copy-of select="@ondblclick"/>
   243 			<xsl:copy-of select="@onfocus"/>
   244 			<xsl:copy-of select="@onmousedown"/>
   245 			<xsl:copy-of select="@onmousemove"/>
   246 			<xsl:copy-of select="@onmouseout"/>
   247 			<xsl:copy-of select="@onmouseover"/>
   248 			<xsl:copy-of select="@onmouseup"/>
   249 			<xsl:copy-of select="@onkeydown"/>
   250 			<xsl:copy-of select="@onkeypress"/>
   251 			<xsl:copy-of select="@onkeyup"/>
   252 			
   253 			<xsl:attribute name="href"><xsl:value-of select="$url"/></xsl:attribute>
   254 			<xsl:apply-templates/>
   255 		</a>
   256 	</xsl:template>
   257 
   258 </xsl:stylesheet>
   259