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