]> Lady’s Gitweb - Shushe/blob - parsers/record-jar.xslt
Add a parser for Pipe‐Separated Jar format
[Shushe] / parsers / record-jar.xslt
1 <?xml version="1.0"?>
2 <!--
3 SPDX-FileCopyrightText: 2024, 2026 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
5 -->
6 <!--
7 ⁌ ⛩📰 书社 ∷ parsers/record-jar.xslt
8
9 © 2024, 2026 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:exslset="http://exslt.org/sets"
21 xmlns:exslstr="http://exslt.org/strings"
22 xmlns:html="&xhtml;"
23 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
24 extension-element-prefixes="exsl exslset exslstr"
25 version="1.0"
26 >
27 <书社:id>urn:fdc:ladys.computer:20231231:Shu1She4:record-jar.xslt</书社:id>
28 <template match="html:script[@type='text/record-jar']">
29 <variable name="lines" select="exslstr:tokenize(., '&#xA;&#xD;')[not(normalize-space(.)='')]"/>
30 <element name="div" namespace="&xhtml;">
31 <if test="starts-with($lines[1], '%%') and $lines[1]!='%%'">
32 <comment>
33 <value-of select="substring-after($lines[1], '%%')"/>
34 </comment>
35 </if>
36 <for-each select="$lines[not(position()=1) and starts-with(., '%%')]">
37 <variable name="end" select="."/>
38 <variable name="start" select="preceding-sibling::*[starts-with(., '%%')][1]"/>
39 <variable name="fields" select="exslset:intersection(exslset:trailing($end/preceding-sibling::*, $start), $lines)"/>
40 <if test="$fields">
41 <element name="dl" namespace="&xhtml;">
42 <for-each select="$fields">
43 <variable name="following" select="exslset:intersection($fields, following-sibling::*)"/>
44 <choose>
45 <when test="contains(' &#x9;', substring(., 1, 1)) and exslset:has-same-node($fields, preceding-sibling::*[1])"/>
46 <otherwise>
47 <variable name="next" select="$following[not(contains(' &#x9;', substring(., 1, 1)))][1]"/>
48 <element name="div" namespace="&xhtml;">
49 <element name="dt" namespace="&xhtml;">
50 <value-of select="normalize-space(substring-before(., ':'))"/>
51 </element>
52 <element name="dd" namespace="&xhtml;">
53 <variable name="firstline">
54 <choose>
55 <when test="contains(., ':')">
56 <value-of select="normalize-space(substring-after(., ':'))"/>
57 </when>
58 <otherwise>
59 <value-of select="normalize-space(.)"/>
60 </otherwise>
61 </choose>
62 </variable>
63 <choose>
64 <when test="substring($firstline, string-length($firstline))='\' and $following[position()=1 and contains(' &#x9;', substring(., 1, 1))]">
65 <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
66 </when>
67 <otherwise>
68 <value-of select="$firstline"/>
69 </otherwise>
70 </choose>
71 <for-each select="exslset:leading($following, $next)[contains(' &#x9;', substring(., 1, 1))]">
72 <variable name="nextline" select="normalize-space(.)"/>
73 <choose>
74 <when test="substring($nextline, string-length($nextline))='\' and exslset:intersection($fields, following-sibling::*)[position()=1 and contains(' &#x9;', substring(., 1, 1))]">
75 <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
76 </when>
77 <otherwise>
78 <value-of select="$nextline"/>
79 </otherwise>
80 </choose>
81 </for-each>
82 </element>
83 </element>
84 </otherwise>
85 </choose>
86 </for-each>
87 </element>
88 </if>
89 <if test="substring-after(., '%%')!=''">
90 <comment>
91 <value-of select="substring-after(., '%%')"/>
92 </comment>
93 </if>
94 </for-each>
95 </element>
96 </template>
97 </transform>
This page took 0.3487 seconds and 5 git commands to generate.