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 [@ Lady’s 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="rows" select="exslstr:tokenize(., '
')[normalize-space(.)!='' and not(starts-with(., '#'))]"/>
27 <variable name="head" select="$rows[1]"/>
28 <variable name="headcols">
29 <call-template name="书社:split">
30 <with-param name="source" select="string($head)"/>
31 <with-param name="separator" select="'	'"/>
34 <variable name="body" select="$rows[not(position()=1)]"/>
38 <for-each select="exsl:node-set($headcols)/*">
40 <value-of select="."/>
46 <for-each select="$body">
47 <variable name="cols">
48 <call-template name="书社:split">
49 <with-param name="source" select="string(.)"/>
50 <with-param name="separator" select="'	'"/>
54 <for-each select="exsl:node-set($cols)/*[count(exsl:node-set($headcols)/*)>=position()]">
56 <attribute name="data-tsv-header">
57 <value-of select="exsl:node-set($headcols)/*[count(current()/preceding-sibling::*)+1]"/>
59 <value-of select="."/>
60 <if test="position()=count(exsl:node-set($headcols)/*)">
61 <for-each select="following-sibling::*">
63 <value-of select="."/>
68 <for-each select="exsl:node-set($headcols)/*[position()>count(exsl:node-set($cols)/*)]">