šablona/makra/odkazy.xsl
author František Kučera <franta-hg@frantovo.cz>
Sun, 08 Jan 2012 16:52:30 +0100
changeset 76 c7746d95283d
parent 71 895757141bff
child 81 8014586c97da
permissions -rw-r--r--
Rozdělení knihovny funkcí podle maker, ve kterých se funkce používají. #8
     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:xs="http://www.w3.org/2001/XMLSchema"
    23 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    24 	exclude-result-prefixes="m xs">
    25 
    26 	<!--
    27 		Interní odkazy
    28 		**************
    29 		Slouží k vkládání odkazů na jiné stránky v rámci webu.
    30 		*
    31 		@href zadáváme jen název souboru bez přípony – s nezakódovanou češtinou a s mezerami
    32 		@typ nevyplňujeme
    33 	-->
    34 	<xsl:template match="m:a[not(@typ)]">
    35 		<a>
    36 			<xsl:copy-of select="@*"/>
    37 			<xsl:attribute name="href">
    38 				<xsl:value-of select="encode-for-uri(concat(@href, $výstupníPřípona))"/>
    39 			</xsl:attribute>
    40 			<xsl:apply-templates/>
    41 		</a>
    42 	</xsl:template>
    43 
    44 	<xsl:variable name="tracURL" select="'https://trac.frantovo.cz/xml-web-generator'"/>	
    45 
    46 	<!--
    47 		Trac – wiki
    48 		***********
    49 		Odkazy na Trac našeho generátoru.
    50 		*
    51 		@href nečíselné parametry vedou do wiki
    52 	-->
    53 	<xsl:template match="m:a[@typ='trac' and not(number(@href))]">
    54 		<xsl:call-template name="vložOdkaz">
    55 			<xsl:with-param name="url" select="
    56 				concat(
    57 					$tracURL, '/wiki/', 
    58 					m:escapuj-url-zachovej-lomítka(@href)
    59 				)"/>
    60 		</xsl:call-template>		
    61 	</xsl:template>
    62 
    63 	<!--
    64 		Trac – úkoly
    65 		************
    66 		Odkazy na Trac našeho generátoru.
    67 		*
    68 		@href číselné parametry vedou na úkoly
    69 	-->
    70 	<xsl:template match="m:a[@typ='trac' and number(@href)]">
    71 		<xsl:call-template name="vložOdkaz">
    72 			<xsl:with-param name="url" select="
    73 				concat(
    74 					$tracURL, '/ticket/', 
    75 					@href
    76 				)"/>
    77 		</xsl:call-template>
    78 	</xsl:template>
    79 
    80 	<!--
    81 		Zdroják
    82 		*******
    83 		Odkazy zdrojový kód našeho generátoru.
    84 		*
    85 		@href název souboru
    86 		@řádek číslo řádku (volitelně)
    87 	-->
    88 	<xsl:template match="m:a[@typ='zdroják' and (not(@řádek) or number(@řádek))]">
    89 		<xsl:call-template name="vložOdkaz">
    90 			<xsl:with-param name="url" select="
    91 				concat(
    92 					$tracURL, '/browser/', 
    93 					m:escapuj-url-zachovej-lomítka(@href),
    94 					'#L',
    95 					(@řádek,'1')[1]
    96 				)"/>
    97 		</xsl:call-template>
    98 	</xsl:template>
    99 	
   100 	<!--
   101 		Wikipedia
   102 		*********
   103 		Stránka v encyklopedii.
   104 		*
   105 		@href název stránky
   106 		@jazyk kód jazyka (výchozí je čeština)
   107 	-->
   108 	<xsl:template match="m:a[@typ='wiki']">
   109 		<xsl:call-template name="vložOdkaz">
   110 			<xsl:with-param name="url" select="
   111 				concat(
   112 					'https://secure.wikimedia.org/wikipedia/', (@jazyk,'cs')[1], '/wiki/', 
   113 					encode-for-uri(@href)
   114 				)"/>
   115 		</xsl:call-template>
   116 	</xsl:template>
   117 	
   118 	<!--
   119 		Javadoc
   120 		*******
   121 		Dokumentace k javovským třídám.
   122 		*
   123 		@href jméno třídy včetně balíčku – např. java.lang.String
   124 		@verze verze Javy, výchozí: 7
   125 	-->
   126 	<xsl:template match="m:a[@typ='javadoc']">
   127 		<xsl:call-template name="vložOdkaz">
   128 			<xsl:with-param name="url" select="
   129 				concat(
   130 					'http://docs.oracle.com/javase/', (@verze,'7')[1], '/docs/api/',
   131 					replace(@href, '\.', '/'),
   132 					'.html'
   133 				)"/>
   134 		</xsl:call-template>
   135 	</xsl:template>
   136 	
   137 	<!-- 
   138 		Seznam.cz
   139 		*********
   140 		Vyhledávání pomocí Seznamu.
   141 		*
   142 		@href náš dotaz
   143 	-->
   144 	<xsl:template match="m:a[@typ='seznam']">
   145 		<xsl:call-template name="vložOdkaz">
   146 			<xsl:with-param name="url" select="
   147 				concat(
   148 					'http://search.seznam.cz/?q=', 
   149 					encode-for-uri(@href)
   150 				)"/>
   151 		</xsl:call-template>
   152 	</xsl:template>
   153 
   154 	<!-- 
   155 		Google.com
   156 		**********
   157 		Vyhledávání pomocí Googlu.
   158 		*
   159 		@href náš dotaz
   160 	-->
   161 	<xsl:template match="m:a[@typ='google']">
   162 		<xsl:call-template name="vložOdkaz">
   163 			<xsl:with-param name="url" select="
   164 				concat(
   165 					'https://encrypted.google.com/search?q=', 
   166 					encode-for-uri(@href)
   167 				)"/>
   168 		</xsl:call-template>	
   169 	</xsl:template>
   170 	
   171 	<!-- 
   172 		Request for comments
   173 		********************
   174 		Internetové standardy – RFC.
   175 		*
   176 		@href číslo RFCčka
   177 	-->
   178 	<xsl:template match="m:a[@typ='rfc' and number(@href)]">
   179 		<xsl:call-template name="vložOdkaz">
   180 			<xsl:with-param name="url" select="
   181 				concat(
   182 					'https://tools.ietf.org/html/rfc',
   183 					@href
   184 				)"/>
   185 		</xsl:call-template>
   186 	</xsl:template>
   187 	
   188 	
   189 	<xsl:template name="vložOdkaz">
   190 		<xsl:param name="url"/>
   191 		<a>
   192 			<!-- Zachováme pouze povolené atributy: -->
   193 			
   194 			<xsl:copy-of select="@charset"/>
   195 			<xsl:copy-of select="@coords"/>
   196 			<xsl:copy-of select="@hreflang"/>
   197 			<xsl:copy-of select="@name"/>
   198 			<xsl:copy-of select="@rel"/>
   199 			<xsl:copy-of select="@rev"/>
   200 			<xsl:copy-of select="@shape"/>
   201 			<xsl:copy-of select="@target"/> <!-- Pozor: nepatří do striktního XHTML -->
   202 			
   203 			<xsl:copy-of select="@accesskey"/>
   204 			<xsl:copy-of select="@class"/>
   205 			<xsl:copy-of select="@dir"/>
   206 			<xsl:copy-of select="@id"/>
   207 			<xsl:copy-of select="@lang"/>
   208 			<xsl:copy-of select="@style"/>
   209 			<xsl:copy-of select="@tabindex"/>
   210 			<xsl:copy-of select="@title"/>
   211 			<xsl:copy-of select="@xml:lang"/>
   212 			
   213 			<xsl:copy-of select="@onblur"/>
   214 			<xsl:copy-of select="@onclick"/>
   215 			<xsl:copy-of select="@ondblclick"/>
   216 			<xsl:copy-of select="@onfocus"/>
   217 			<xsl:copy-of select="@onmousedown"/>
   218 			<xsl:copy-of select="@onmousemove"/>
   219 			<xsl:copy-of select="@onmouseout"/>
   220 			<xsl:copy-of select="@onmouseover"/>
   221 			<xsl:copy-of select="@onmouseup"/>
   222 			<xsl:copy-of select="@onkeydown"/>
   223 			<xsl:copy-of select="@onkeypress"/>
   224 			<xsl:copy-of select="@onkeyup"/>
   225 			
   226 			<xsl:attribute name="href"><xsl:value-of select="$url"/></xsl:attribute>
   227 			<xsl:apply-templates/>
   228 		</a>
   229 	</xsl:template>
   230 
   231 </xsl:stylesheet>