]> Lady’s Gitweb - Shushe/blob - parsers/tsv.xslt
Use <书社:apply-attributes-to-root> to add version
[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 <transform
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"
21 version="1.0"
22 >
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(., '&#xA;')"/>
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="'&#x9;'"/>
32 </call-template>
33 </variable>
34 <html:table>
35 <for-each select="$lines[starts-with(., '#') and following-sibling::*[generate-id(.)=generate-id($head)]]">
36 <comment>
37 <value-of select="substring-after(., '#')"/>
38 </comment>
39 </for-each>
40 <html:thead>
41 <html:tr>
42 <for-each select="exsl:node-set($headcols)/*">
43 <html:th scope="col">
44 <value-of select="."/>
45 </html:th>
46 </for-each>
47 </html:tr>
48 </html:thead>
49 <html:tbody>
50 <for-each select="$head/following-sibling::*[normalize-space(.)!='']">
51 <choose>
52 <when test="starts-with(., '#')">
53 <comment>
54 <value-of select="substring-after(., '#')"/>
55 </comment>
56 </when>
57 <otherwise>
58 <variable name="cols">
59 <call-template name="书社:split">
60 <with-param name="source" select="string(.)"/>
61 <with-param name="separator" select="'&#x9;'"/>
62 </call-template>
63 </variable>
64 <html:tr>
65 <for-each select="exsl:node-set($cols)/*[count(exsl:node-set($headcols)/*)>=position()]">
66 <html:td>
67 <attribute name="data-tsv-header">
68 <value-of select="exsl:node-set($headcols)/*[count(current()/preceding-sibling::*)+1]"/>
69 </attribute>
70 <value-of select="."/>
71 <if test="position()=count(exsl:node-set($headcols)/*)">
72 <for-each select="following-sibling::*">
73 <text>&#x9;</text>
74 <value-of select="."/>
75 </for-each>
76 </if>
77 </html:td>
78 </for-each>
79 <for-each select="exsl:node-set($headcols)/*[position()>count(exsl:node-set($cols)/*)]">
80 <html:td/>
81 </for-each>
82 </html:tr>
83 </otherwise>
84 </choose>
85 </for-each>
86 </html:tbody>
87 </html:table>
88 </template>
89 </transform>
This page took 0.095061 seconds and 5 git commands to generate.