]> Lady’s Gitweb - Shushe/blob - parsers/tsv.xslt
Improve (fix) the T·S·V parser
[Shushe] / parsers / tsv.xslt
1 <?xml version="1.0"?>
2 <!--
3 ⁌ ⛩️📰 书社 ∷ parsers/tsv.xslt
4
5 © 2023–2024 Lady [@ Lady’s Computer]
6
7 This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
8 If a copy of the M·P·L was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
9 -->
10 <transform
11 xmlns="http://www.w3.org/1999/XSL/Transform"
12 xmlns:exsl="http://exslt.org/common"
13 xmlns:exslstr="http://exslt.org/strings"
14 xmlns:html="http://www.w3.org/1999/xhtml"
15 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
16 exclude-result-prefixes="exsl exslstr"
17 version="1.0"
18 >
19 <import href="../lib/split.xslt"/>
20 <书社:id>urn:fdc:ladys.computer:20231231:Shu1She4:tsv.xslt</书社:id>
21 <template match="html:script[@type='text/tab-separated-values']">
22 <variable name="rows" select="exslstr:tokenize(., '&#xA;')[normalize-space(.)!='' and not(starts-with(., '#'))]"/>
23 <variable name="head" select="$rows[1]"/>
24 <variable name="headcols">
25 <call-template name="书社:split">
26 <with-param name="source" select="string($head)"/>
27 <with-param name="separator" select="'&#x9;'"/>
28 </call-template>
29 </variable>
30 <variable name="body" select="$rows[not(position()=1)]"/>
31 <html:table>
32 <html:thead>
33 <html:tr>
34 <for-each select="exsl:node-set($headcols)/*">
35 <html:th scope="col">
36 <value-of select="."/>
37 </html:th>
38 </for-each>
39 </html:tr>
40 </html:thead>
41 <html:tbody>
42 <for-each select="$body">
43 <variable name="cols">
44 <call-template name="书社:split">
45 <with-param name="source" select="string(.)"/>
46 <with-param name="separator" select="'&#x9;'"/>
47 </call-template>
48 </variable>
49 <html:tr>
50 <for-each select="exsl:node-set($cols)/*[count(exsl:node-set($headcols)/*)>position()]">
51 <html:td>
52 <value-of select="."/>
53 <if test="position()=count(exsl:node-set($headcols)/*)">
54 <for-each select="following-sibling:*">
55 <text>&#x9;</text>
56 <value-of select="."/>
57 </for-each>
58 </if>
59 </html:td>
60 </for-each>
61 <for-each select="exsl:node-set($headcols)/*[position()>count(exsl:node-set($cols)/*)]">
62 <html:td/>
63 </for-each>
64 </html:tr>
65 </for-each>
66 </html:tbody>
67 </html:table>
68 </template>
69 </transform>
This page took 0.05416 seconds and 5 git commands to generate.