root/šablona/makra/tabulka.xsl @ 90:ae439159d833

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

#15 Tabulky: čísla budou zarovnaná doprava

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:xsl="http://www.w3.org/1999/XSL/Transform"
23        exclude-result-prefixes="m">
24
25        <!--
26                Jednoduché tabulky
27                ******************
28                Data zadáváme do těla elementu.
29                Sloupce oddělujeme tabulátorem (může jich být víc, minimálně však jeden, mezery nestačí).
30                První řádek se považuje za záhlaví (nadpisy sloupců).
31                *
32                @src volitelně můžeme data tabulky načítat ze souboru
33                @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)
34        -->
35        <xsl:template match="m:tabulka">
36                <xsl:call-template name="vykresliTabulku">
37                        <xsl:with-param name="zadání" select="text()"/>
38                        <xsl:with-param name="oddělovač" select="(@oddělovač, '\t+')[1]"/>
39                </xsl:call-template>
40        </xsl:template>
41       
42        <xsl:template match="m:tabulka[@src]">
43                <xsl:call-template name="vykresliTabulku">
44                        <xsl:with-param name="zadání" select="m:načti-textový-soubor(@src)"/>
45                        <xsl:with-param name="oddělovač" select="(@oddělovač, ';')[1]"/>
46                </xsl:call-template>
47        </xsl:template>
48       
49        <xsl:template name="vykresliTabulku">
50                <xsl:param name="zadání"/>
51                <xsl:param name="oddělovač"/>
52                <table>
53                        <xsl:variable name="data" select="replace(replace($zadání, '^\s+', ''),'\s+$','')"/>
54                        <xsl:variable name="hlavička" select="substring-before($data, '&#10;')"/>
55                        <xsl:variable name="tělo" select="substring-after($data, '&#10;')"/>
56                        <thead>
57                                <tr>
58                                        <xsl:for-each select="tokenize($hlavička, $oddělovač)">
59                                                <xsl:if test="normalize-space(.)">
60                                                        <td><xsl:value-of select="normalize-space(.)"/></td>
61                                                </xsl:if>
62                                        </xsl:for-each>
63                                </tr>
64                        </thead>
65                        <tbody>
66                                <xsl:for-each select="tokenize($tělo, '\n')">
67                                        <xsl:if test="normalize-space(.)">
68                                                <tr>
69                                                        <xsl:for-each select="tokenize(., $oddělovač)">
70                                                                <xsl:if test="normalize-space(.)">
71                                                                        <xsl:element name="td">
72                                                                                <xsl:if test="number(normalize-space(.))">
73                                                                                        <xsl:attribute name="class">číslo</xsl:attribute>
74                                                                                </xsl:if>
75                                                                                <xsl:value-of select="normalize-space(.)"/>
76                                                                        </xsl:element>
77                                                                </xsl:if>
78                                                        </xsl:for-each>
79                                                </tr>
80                                        </xsl:if>
81                                </xsl:for-each>
82                        </tbody>
83                </table>
84        </xsl:template>
85
86</xsl:stylesheet>
87
Note: See TracBrowser for help on using the browser.