root/šablona/makra/tabulka.xsl @ 136:d5feb9d8ebc3

Revision 136:d5feb9d8ebc3, 3.7 KB (checked in by František Kučera <franta-hg@…>, 5 years ago)

fix license version: GNU GPLv3

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, version 3 of the License.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program.  If not, see <http://www.gnu.org/licenses/>.
17-->
18<xsl:stylesheet version="2.0"
19        xmlns="http://www.w3.org/1999/xhtml"
20        xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"
21        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
22        exclude-result-prefixes="m">
23
24        <!--
25                Jednoduché tabulky
26                ******************
27                Data zadáváme do těla elementu.
28                Sloupce oddělujeme tabulátorem (může jich být víc, minimálně však jeden, mezery nestačí).
29                První řádek se považuje za záhlaví (nadpisy sloupců).
30                *
31                @src volitelně můžeme data tabulky načítat ze souboru
32                @oddělovač regulární výraz, který odděluje sloupce – např. „\t+“ pro tabulátory (výchozí pro tabulky vložené přímo do stránky) nebo „;“ pro středník (výchozí pro tabulky načítané ze souboru)
33        -->
34        <xsl:template match="m:tabulka">
35                <xsl:call-template name="vykresliTabulku">
36                        <xsl:with-param name="zadání" select="text()"/>
37                        <xsl:with-param name="oddělovač" select="(@oddělovač, '\t+')[1]"/>
38                </xsl:call-template>
39        </xsl:template>
40       
41        <!-- Skript je potřeba interpretovat ještě před tabulkou – ostatní makra budou interpretovat uvnitř buněk -->
42        <xsl:template match="m:tabulka[m:skript]">
43                <xsl:variable name="zadání">
44                        <xsl:apply-templates select="*"/>
45                </xsl:variable>
46                <xsl:call-template name="vykresliTabulku">
47                        <xsl:with-param name="zadání" select="$zadání"/>
48                        <xsl:with-param name="oddělovač" select="(@oddělovač, '\t+')[1]"/>
49                </xsl:call-template>
50        </xsl:template>
51       
52        <!-- Tabulka načítaná ze souboru: -->
53        <xsl:template match="m:tabulka[@src]">
54                <xsl:call-template name="vykresliTabulku">
55                        <xsl:with-param name="zadání" select="m:načti-textový-soubor(@src)"/>
56                        <xsl:with-param name="oddělovač" select="(@oddělovač, ';')[1]"/>
57                </xsl:call-template>
58        </xsl:template>
59       
60        <!-- TODO: Umožnit použití maker a značek uvnitř buněk tabulky. -->
61        <xsl:template name="vykresliTabulku">
62                <xsl:param name="zadání"/>
63                <xsl:param name="oddělovač"/>
64                <table>
65                        <xsl:variable name="data" select="replace(replace($zadání, '^\s+', ''),'\s+$','')"/>
66                        <xsl:variable name="hlavička" select="substring-before($data, '&#10;')"/>
67                        <xsl:variable name="tělo" select="substring-after($data, '&#10;')"/>
68                        <thead>
69                                <tr>
70                                        <xsl:for-each select="tokenize($hlavička, $oddělovač)">
71                                                <xsl:if test="normalize-space(.)">
72                                                        <td><xsl:value-of select="normalize-space(.)"/></td>
73                                                </xsl:if>
74                                        </xsl:for-each>
75                                </tr>
76                        </thead>
77                        <tbody>
78                                <xsl:for-each select="tokenize($tělo, '\n')">
79                                        <xsl:if test="normalize-space(.)">
80                                                <tr>
81                                                        <xsl:for-each select="tokenize(., $oddělovač)">
82                                                                <xsl:if test="normalize-space(.)">
83                                                                        <xsl:element name="td">
84                                                                                <xsl:if test="number(normalize-space(.))">
85                                                                                        <xsl:attribute name="class">číslo</xsl:attribute>
86                                                                                </xsl:if>
87                                                                                <xsl:value-of select="normalize-space(.)"/>
88                                                                        </xsl:element>
89                                                                </xsl:if>
90                                                        </xsl:for-each>
91                                                </tr>
92                                        </xsl:if>
93                                </xsl:for-each>
94                        </tbody>
95                </table>
96        </xsl:template>
97
98</xsl:stylesheet>
99
Note: See TracBrowser for help on using the browser.