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 xmlns="http://www.w3.org/1999/XSL/Transform"
16 xmlns:exsl="http://exslt.org/common"
17 xmlns:exslstr="http://exslt.org/strings"
18 xmlns:html="http://www.w3.org/1999/xhtml"
19 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
20 extension-element-prefixes="exsl exslstr"
23 <import href="../lib/split.xslt"/>
24 <书社:id>urn:fdc:ladys.computer:20231231:Shu1She4:tsv.xslt</书社:id>
25 <template match="html:script[@type='text/tab-separated-values']">
26 <variable name="lines" select="exslstr:tokenize(., '
')"/>
27 <variable name="head" select="$lines[normalize-space(.)!='' and not(starts-with(., '#'))][1]"/>
28 <variable name="headcols">
29 <call-template name="书社:split">
30 <with-param name="source" select="string($head)"/>
31 <with-param name="separator" select="'	'"/>
35 <for-each select="$lines[starts-with(., '#') and following-sibling::*[generate-id(.)=generate-id($head)]]">
37 <value-of select="substring-after(., '#')"/>
42 <for-each select="exsl:node-set($headcols)/*">
44 <value-of select="."/>
50 <for-each select="$head/following-sibling::*[normalize-space(.)!='']">
52 <when test="starts-with(., '#')">
54 <value-of select="substring-after(., '#')"/>
58 <variable name="cols">
59 <call-template name="书社:split">
60 <with-param name="source" select="string(.)"/>
61 <with-param name="separator" select="'	'"/>
65 <for-each select="exsl:node-set($cols)/*[count(exsl:node-set($headcols)/*)>=position()]">
67 <attribute name="data-tsv-header">
68 <value-of select="exsl:node-set($headcols)/*[count(current()/preceding-sibling::*)+1]"/>
70 <value-of select="."/>
71 <if test="position()=count(exsl:node-set($headcols)/*)">
72 <for-each select="following-sibling::*">
74 <value-of select="."/>
79 <for-each select="exsl:node-set($headcols)/*[position()>count(exsl:node-set($cols)/*)]">