root/šablona/makra/odkazy.xsl @ 66:a8085dedd92b

Revision 66:a8085dedd92b, 6.3 KB (checked in by František Kučera <franta-hg@…>, 12 years ago)

Odkazy #16: oprava chyby: Zachováme pouze povolené atributy.

Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3XML Web generátor – program na generování webových stránek
4Copyright © 2012 František Kučera (frantovo.cz)
5
6This program is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along 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        <xsl:function name="m:escapuj-url-zachovej-lomítka" as="xs:string">
101                <xsl:param name="cesta"/>
102                <xsl:value-of select="replace(encode-for-uri($cesta), '%2F', '/')"/>
103        </xsl:function>
104
105        <!--
106                Wikipedia
107                *********
108                Stránka v encyklopedii.
109                *
110                @href název stránky
111                @jazyk kód jazyka (výchozí je čeština)
112        -->
113        <xsl:template match="m:a[@typ='wiki']">
114                <xsl:call-template name="vložOdkaz">
115                        <xsl:with-param name="url" select="
116                                concat(
117                                        'https://secure.wikimedia.org/wikipedia/', (@jazyk,'cs')[1], '/wiki/',
118                                        encode-for-uri(@href)
119                                )"/>
120                </xsl:call-template>
121        </xsl:template>
122       
123        <!--
124                Javadoc
125                *******
126                Dokumentace k javovským třídám.
127                *
128                @href jméno třídy včetně balíčku – např. java.lang.String
129                @verze verze Javy, výchozí: 7
130        -->
131        <xsl:template match="m:a[@typ='javadoc']">
132                <xsl:call-template name="vložOdkaz">
133                        <xsl:with-param name="url" select="
134                                concat(
135                                        'http://docs.oracle.com/javase/', (@verze,'7')[1], '/docs/api/',
136                                        replace(@href, '\.', '/'),
137                                        '.html'
138                                )"/>
139                </xsl:call-template>
140        </xsl:template>
141       
142        <!--
143                Seznam.cz
144                *********
145                Vyhledávání pomocí Seznamu.
146                *
147                @href náš dotaz
148        -->
149        <xsl:template match="m:a[@typ='seznam']">
150                <xsl:call-template name="vložOdkaz">
151                        <xsl:with-param name="url" select="
152                                concat(
153                                        'http://search.seznam.cz/?q=',
154                                        encode-for-uri(@href)
155                                )"/>
156                </xsl:call-template>
157        </xsl:template>
158
159        <!--
160                Google.com
161                **********
162                Vyhledávání pomocí Googlu.
163                *
164                @href náš dotaz
165        -->
166        <xsl:template match="m:a[@typ='google']">
167                <xsl:call-template name="vložOdkaz">
168                        <xsl:with-param name="url" select="
169                                concat(
170                                        'https://encrypted.google.com/search?q=',
171                                        encode-for-uri(@href)
172                                )"/>
173                </xsl:call-template>   
174        </xsl:template>
175       
176        <!--
177                Request for comments
178                ********************
179                Internetové standardy – RFC.
180                *
181                @href číslo RFCčka
182        -->
183        <xsl:template match="m:a[@typ='rfc' and number(@href)]">
184                <xsl:call-template name="vložOdkaz">
185                        <xsl:with-param name="url" select="
186                                concat(
187                                        'https://tools.ietf.org/html/rfc',
188                                        @href
189                                )"/>
190                </xsl:call-template>
191        </xsl:template>
192       
193       
194        <xsl:template name="vložOdkaz">
195                <xsl:param name="url"/>
196                <a>
197                        <!-- Zachováme pouze povolené atributy: -->
198                       
199                        <xsl:copy-of select="@charset"/>
200                        <xsl:copy-of select="@coords"/>
201                        <xsl:copy-of select="@hreflang"/>
202                        <xsl:copy-of select="@name"/>
203                        <xsl:copy-of select="@rel"/>
204                        <xsl:copy-of select="@rev"/>
205                        <xsl:copy-of select="@shape"/>
206                        <xsl:copy-of select="@target"/> <!-- Pozor: nepatří do striktního XHTML -->
207                       
208                        <xsl:copy-of select="@accesskey"/>
209                        <xsl:copy-of select="@class"/>
210                        <xsl:copy-of select="@dir"/>
211                        <xsl:copy-of select="@id"/>
212                        <xsl:copy-of select="@lang"/>
213                        <xsl:copy-of select="@style"/>
214                        <xsl:copy-of select="@tabindex"/>
215                        <xsl:copy-of select="@title"/>
216                        <xsl:copy-of select="@xml:lang"/>
217                       
218                        <xsl:copy-of select="@onblur"/>
219                        <xsl:copy-of select="@onclick"/>
220                        <xsl:copy-of select="@ondblclick"/>
221                        <xsl:copy-of select="@onfocus"/>
222                        <xsl:copy-of select="@onmousedown"/>
223                        <xsl:copy-of select="@onmousemove"/>
224                        <xsl:copy-of select="@onmouseout"/>
225                        <xsl:copy-of select="@onmouseover"/>
226                        <xsl:copy-of select="@onmouseup"/>
227                        <xsl:copy-of select="@onkeydown"/>
228                        <xsl:copy-of select="@onkeypress"/>
229                        <xsl:copy-of select="@onkeyup"/>
230                       
231                        <xsl:attribute name="href"><xsl:value-of select="$url"/></xsl:attribute>
232                        <xsl:apply-templates/>
233                </a>
234        </xsl:template>
235
236</xsl:stylesheet>
Note: See TracBrowser for help on using the browser.