franta-hg@51
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
franta-hg@61
|
2 |
<!--
|
franta-hg@61
|
3 |
XML Web generátor – program na generování webových stránek
|
franta-hg@61
|
4 |
Copyright © 2012 František Kučera (frantovo.cz)
|
franta-hg@61
|
5 |
|
franta-hg@61
|
6 |
This program is free software: you can redistribute it and/or modify
|
franta-hg@61
|
7 |
it under the terms of the GNU General Public License as published by
|
franta-hg@61
|
8 |
the Free Software Foundation, either version 3 of the License, or
|
franta-hg@61
|
9 |
(at your option) any later version.
|
franta-hg@61
|
10 |
|
franta-hg@61
|
11 |
This program is distributed in the hope that it will be useful,
|
franta-hg@61
|
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
franta-hg@61
|
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
franta-hg@61
|
14 |
GNU General Public License for more details.
|
franta-hg@61
|
15 |
|
franta-hg@61
|
16 |
You should have received a copy of the GNU General Public License
|
franta-hg@61
|
17 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
franta-hg@61
|
18 |
-->
|
franta-hg@51
|
19 |
<xsl:stylesheet version="2.0"
|
franta-hg@71
|
20 |
xmlns="http://www.w3.org/1999/xhtml"
|
franta-hg@71
|
21 |
xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"
|
franta-hg@71
|
22 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
franta-hg@71
|
23 |
exclude-result-prefixes="m">
|
franta-hg@70
|
24 |
|
franta-hg@51
|
25 |
<!--
|
franta-hg@51
|
26 |
Jednoduché tabulky
|
franta-hg@51
|
27 |
******************
|
franta-hg@51
|
28 |
Data zadáváme do těla elementu.
|
franta-hg@51
|
29 |
Sloupce oddělujeme tabulátorem (může jich být víc, minimálně však jeden, mezery nestačí).
|
franta-hg@51
|
30 |
První řádek se považuje za záhlaví (nadpisy sloupců).
|
franta-hg@51
|
31 |
*
|
franta-hg@70
|
32 |
@src volitelně můžeme data tabulky načítat ze souboru
|
franta-hg@70
|
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)
|
franta-hg@51
|
34 |
-->
|
franta-hg@70
|
35 |
<xsl:template match="m:tabulka">
|
franta-hg@70
|
36 |
<xsl:call-template name="vykresliTabulku">
|
franta-hg@70
|
37 |
<xsl:with-param name="zadání" select="text()"/>
|
franta-hg@70
|
38 |
<xsl:with-param name="oddělovač" select="(@oddělovač, '\t+')[1]"/>
|
franta-hg@70
|
39 |
</xsl:call-template>
|
franta-hg@70
|
40 |
</xsl:template>
|
franta-hg@70
|
41 |
|
franta-hg@70
|
42 |
<xsl:template match="m:tabulka[@src]">
|
franta-hg@70
|
43 |
<xsl:call-template name="vykresliTabulku">
|
franta-hg@71
|
44 |
<xsl:with-param name="zadání" select="m:načti-textový-soubor(@src)"/>
|
franta-hg@70
|
45 |
<xsl:with-param name="oddělovač" select="(@oddělovač, ';')[1]"/>
|
franta-hg@70
|
46 |
</xsl:call-template>
|
franta-hg@70
|
47 |
</xsl:template>
|
franta-hg@70
|
48 |
|
franta-hg@70
|
49 |
<xsl:template name="vykresliTabulku">
|
franta-hg@70
|
50 |
<xsl:param name="zadání"/>
|
franta-hg@70
|
51 |
<xsl:param name="oddělovač"/>
|
franta-hg@70
|
52 |
<table>
|
franta-hg@70
|
53 |
<xsl:variable name="data" select="replace(replace($zadání, '^\s+', ''),'\s+$','')"/>
|
franta-hg@70
|
54 |
<xsl:variable name="hlavička" select="substring-before($data, ' ')"/>
|
franta-hg@70
|
55 |
<xsl:variable name="tělo" select="substring-after($data, ' ')"/>
|
franta-hg@70
|
56 |
<thead>
|
franta-hg@70
|
57 |
<tr>
|
franta-hg@70
|
58 |
<xsl:for-each select="tokenize($hlavička, $oddělovač)">
|
franta-hg@70
|
59 |
<xsl:if test="normalize-space(.)">
|
franta-hg@51
|
60 |
<td><xsl:value-of select="normalize-space(.)"/></td>
|
franta-hg@51
|
61 |
</xsl:if>
|
franta-hg@51
|
62 |
</xsl:for-each>
|
franta-hg@70
|
63 |
</tr>
|
franta-hg@70
|
64 |
</thead>
|
franta-hg@70
|
65 |
<tbody>
|
franta-hg@51
|
66 |
<xsl:for-each select="tokenize($tělo, '\n')">
|
franta-hg@51
|
67 |
<xsl:if test="normalize-space(.)">
|
franta-hg@51
|
68 |
<tr>
|
franta-hg@70
|
69 |
<xsl:for-each select="tokenize(., $oddělovač)">
|
franta-hg@51
|
70 |
<xsl:if test="normalize-space(.)">
|
franta-hg@90
|
71 |
<xsl:element name="td">
|
franta-hg@90
|
72 |
<xsl:if test="number(normalize-space(.))">
|
franta-hg@90
|
73 |
<xsl:attribute name="class">číslo</xsl:attribute>
|
franta-hg@90
|
74 |
</xsl:if>
|
franta-hg@90
|
75 |
<xsl:value-of select="normalize-space(.)"/>
|
franta-hg@90
|
76 |
</xsl:element>
|
franta-hg@51
|
77 |
</xsl:if>
|
franta-hg@51
|
78 |
</xsl:for-each>
|
franta-hg@51
|
79 |
</tr>
|
franta-hg@51
|
80 |
</xsl:if>
|
franta-hg@51
|
81 |
</xsl:for-each>
|
franta-hg@70
|
82 |
</tbody>
|
franta-hg@70
|
83 |
</table>
|
franta-hg@70
|
84 |
</xsl:template>
|
franta-hg@51
|
85 |
|
franta-hg@51
|
86 |
</xsl:stylesheet>
|
franta-hg@51
|
87 |
|