]> Lady’s Gitweb - Shushe/blob - parsers/tsv.xslt
Fix time·zone handling
[Shushe] / parsers / tsv.xslt
1 <?xml version="1.0"?>
2 <!--
3 SPDX-FileCopyrightText: 2023, 2024 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
5 -->
6 <!--
7 ⁌ ⛩📰 书社 ∷ parsers/tsv.xslt
8
9 © 2023–2024 Lady [@ Ladys Computer].
10
11 This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
12 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/>.
13 -->
14 <!DOCTYPE transform [
15 <!ENTITY xhtml 'http://www.w3.org/1999/xhtml'>
16 ]>
17 <transform
18 xmlns="http://www.w3.org/1999/XSL/Transform"
19 xmlns:exsl="http://exslt.org/common"
20 xmlns:exslstr="http://exslt.org/strings"
21 xmlns:html="&xhtml;"
22 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
23 extension-element-prefixes="exsl exslstr"
24 version="1.0"
25 >
26 <import href="../lib/split.xslt"/>
27 <书社:id>urn:fdc:ladys.computer:20231231:Shu1She4:tsv.xslt</书社:id>
28 <template match="html:script[@type='text/tab-separated-values']">
29 <variable name="lines" select="exslstr:tokenize(., '&#xA;')"/>
30 <variable name="head" select="$lines[normalize-space(.)!='' and not(starts-with(., '#'))][1]"/>
31 <variable name="headcols">
32 <call-template name="书社:split">
33 <with-param name="source" select="string($head)"/>
34 <with-param name="separator" select="'&#x9;'"/>
35 </call-template>
36 </variable>
37 <element name="table" namespace="&xhtml;">
38 <for-each select="$lines[starts-with(., '#') and following-sibling::*[generate-id(.)=generate-id($head)]]">
39 <comment>
40 <value-of select="substring-after(., '#')"/>
41 </comment>
42 </for-each>
43 <element name="thead" namespace="&xhtml;">
44 <element name="tr" namespace="&xhtml;">
45 <for-each select="exsl:node-set($headcols)/*">
46 <element name="th" namespace="&xhtml;">
47 <attribute name="scope">
48 <text>col</text>
49 </attribute>
50 <value-of select="."/>
51 </element>
52 </for-each>
53 </element>
54 </element>
55 <element name="tbody" namespace="&xhtml;">
56 <for-each select="$head/following-sibling::*[normalize-space(.)!='']">
57 <choose>
58 <when test="starts-with(., '#')">
59 <comment>
60 <value-of select="substring-after(., '#')"/>
61 </comment>
62 </when>
63 <otherwise>
64 <variable name="cols">
65 <call-template name="书社:split">
66 <with-param name="source" select="string(.)"/>
67 <with-param name="separator" select="'&#x9;'"/>
68 </call-template>
69 </variable>
70 <element name="tr" namespace="&xhtml;">
71 <for-each select="exsl:node-set($cols)/*[count(exsl:node-set($headcols)/*)>=position()]">
72 <element name="td" namespace="&xhtml;">
73 <attribute name="data-tsv-header">
74 <value-of select="exsl:node-set($headcols)/*[count(current()/preceding-sibling::*)+1]"/>
75 </attribute>
76 <value-of select="."/>
77 <if test="position()=count(exsl:node-set($headcols)/*)">
78 <for-each select="following-sibling::*">
79 <text>&#x9;</text>
80 <value-of select="."/>
81 </for-each>
82 </if>
83 </element>
84 </for-each>
85 <for-each select="exsl:node-set($headcols)/*[position()>count(exsl:node-set($cols)/*)]">
86 <element name="td" namespace="&xhtml;"/>
87 </for-each>
88 </element>
89 </otherwise>
90 </choose>
91 </for-each>
92 </element>
93 </element>
94 </template>
95 </transform>
This page took 0.065397 seconds and 5 git commands to generate.