3 SPDX-FileCopyrightText: 2023, 2024 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
7 ⁌ ⛩📰 书社 ∷ parsers/tsv.xslt
9 © 2023–2024 Lady [@ Ladys Computer].
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/>.
15 <!ENTITY xhtml 'http://www.w3.org/1999/xhtml'>
18 xmlns="http://www.w3.org/1999/XSL/Transform"
19 xmlns:exsl="http://exslt.org/common"
20 xmlns:exslstr="http://exslt.org/strings"
22 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
23 extension-element-prefixes="exsl exslstr"
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(., '
')"/>
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="'	'"/>
37 <element name="table" namespace="&xhtml;">
38 <for-each select="$lines[starts-with(., '#') and following-sibling::*[generate-id(.)=generate-id($head)]]">
40 <value-of select="substring-after(., '#')"/>
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">
50 <value-of select="."/>
55 <element name="tbody" namespace="&xhtml;">
56 <for-each select="$head/following-sibling::*[normalize-space(.)!='']">
58 <when test="starts-with(., '#')">
60 <value-of select="substring-after(., '#')"/>
64 <variable name="cols">
65 <call-template name="书社:split">
66 <with-param name="source" select="string(.)"/>
67 <with-param name="separator" select="'	'"/>
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]"/>
76 <value-of select="."/>
77 <if test="position()=count(exsl:node-set($headcols)/*)">
78 <for-each select="following-sibling::*">
80 <value-of select="."/>
85 <for-each select="exsl:node-set($headcols)/*[position()>count(exsl:node-set($cols)/*)]">
86 <element name="td" namespace="&xhtml;"/>