]> Lady’s Gitweb - Shushe/blobdiff - parsers/record-jar.xslt
Improvements to Record Jar parsing
[Shushe] / parsers / record-jar.xslt
index abaf08c04e450c09331cc81e3d55722448cc1ae6..216a2a6930595fa1df0542e9039a677444e66a98 100644 (file)
@@ -1,30 +1,34 @@
 <?xml version="1.0"?>
 <!--
 <?xml version="1.0"?>
 <!--
-SPDX-FileCopyrightText: 2024 Lady <https://www.ladys.computer/about/#lady>
+SPDX-FileCopyrightText: 2024, 2026 Lady <https://www.ladys.computer/about/#lady>
 SPDX-License-Identifier: MPL-2.0
 -->
 <!--
 ⁌ ⛩📰 书社 ∷ parsers/record-jar.xslt
 
 SPDX-License-Identifier: MPL-2.0
 -->
 <!--
 ⁌ ⛩📰 书社 ∷ parsers/record-jar.xslt
 
-© 2024 Lady [@ Ladys Computer].
+© 2024, 2026 Lady [@ Ladys Computer].
 
 This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
 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/>.
 -->
 
 This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
 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/>.
 -->
+<!DOCTYPE transform [
+       <!ENTITY xhtml 'http://www.w3.org/1999/xhtml'>
+]>
 <transform
        xmlns="http://www.w3.org/1999/XSL/Transform"
        xmlns:exsl="http://exslt.org/common"
 <transform
        xmlns="http://www.w3.org/1999/XSL/Transform"
        xmlns:exsl="http://exslt.org/common"
+       xmlns:exslset="http://exslt.org/sets"
        xmlns:exslstr="http://exslt.org/strings"
        xmlns:exslstr="http://exslt.org/strings"
-       xmlns:html="http://www.w3.org/1999/xhtml"
+       xmlns:html="&xhtml;"
        xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
        xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
-       extension-element-prefixes="exsl exslstr"
+       extension-element-prefixes="exsl exslset exslstr"
        version="1.0"
 >
        <书社:id>urn:fdc:ladys.computer:20231231:Shu1She4:record-jar.xslt</书社:id>
        <template match="html:script[@type='text/record-jar']">
        version="1.0"
 >
        <书社:id>urn:fdc:ladys.computer:20231231:Shu1She4:record-jar.xslt</书社:id>
        <template match="html:script[@type='text/record-jar']">
-               <variable name="lines" select="exslstr:tokenize(., '&#xA;')"/>
-               <html:div>
-                       <if test="starts-with($lines[1], '%%') and substring-after($lines[1], '%%')!=''">
+               <variable name="lines" select="exslstr:tokenize(., '&#xA;&#xD;')[not(normalize-space(.)='')]"/>
+               <element name="div" namespace="&xhtml;">
+                       <if test="starts-with($lines[1], '%%') and $lines[1]!='%%'">
                                <comment>
                                        <value-of select="substring-after($lines[1], '%%')"/>
                                </comment>
                                <comment>
                                        <value-of select="substring-after($lines[1], '%%')"/>
                                </comment>
@@ -32,19 +36,20 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                        <for-each select="$lines[not(position()=1) and starts-with(., '%%')]">
                                <variable name="end" select="."/>
                                <variable name="start" select="preceding-sibling::*[starts-with(., '%%')][1]"/>
                        <for-each select="$lines[not(position()=1) and starts-with(., '%%')]">
                                <variable name="end" select="."/>
                                <variable name="start" select="preceding-sibling::*[starts-with(., '%%')][1]"/>
-                               <variable name="fields" select="($start/following-sibling::*|$lines[not($start)])[not(preceding-sibling::*[generate-id()=generate-id($end)]) and not(starts-with(., '%%'))]"/>
+                               <variable name="fields" select="exslset:intersection(exslset:trailing($end/preceding-sibling::*, $start), $lines)"/>
                                <if test="$fields">
                                <if test="$fields">
-                                       <html:dl>
+                                       <element name="dl" namespace="&xhtml;">
                                                <for-each select="$fields">
                                                <for-each select="$fields">
+                                                       <variable name="following" select="exslset:intersection($fields, following-sibling::*)"/>
                                                        <choose>
                                                        <choose>
-                                                               <when test="starts-with(., ' ') and $fields[generate-id()=generate-id(current()/preceding-sibling::*[1])]"/>
+                                                               <when test="contains(' &#x9;', substring(., 1, 1)) and exslset:has-same-node($fields, preceding-sibling::*[1])"/>
                                                                <otherwise>
                                                                <otherwise>
-                                                                       <variable name="next" select="following-sibling::*[not(starts-with(., ' '))]"/>
-                                                                       <html:div>
-                                                                               <html:dt>
+                                                                       <variable name="next" select="$following[not(contains(' &#x9;', substring(., 1, 1)))][1]"/>
+                                                                       <element name="div" namespace="&xhtml;">
+                                                                               <element name="dt" namespace="&xhtml;">
                                                                                        <value-of select="normalize-space(substring-before(., ':'))"/>
                                                                                        <value-of select="normalize-space(substring-before(., ':'))"/>
-                                                                               </html:dt>
-                                                                               <html:dd>
+                                                                               </element>
+                                                                               <element name="dd" namespace="&xhtml;">
                                                                                        <variable name="firstline">
                                                                                                <choose>
                                                                                                        <when test="contains(., ':')">
                                                                                        <variable name="firstline">
                                                                                                <choose>
                                                                                                        <when test="contains(., ':')">
@@ -56,17 +61,17 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                                                </choose>
                                                                                        </variable>
                                                                                        <choose>
                                                                                                </choose>
                                                                                        </variable>
                                                                                        <choose>
-                                                                                               <when test="substring($firstline, string-length($firstline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
+                                                                                               <when test="substring($firstline, string-length($firstline))='\' and $following[position()=1 and contains(' &#x9;', substring(., 1, 1))]">
                                                                                                        <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
                                                                                                </when>
                                                                                                <otherwise>
                                                                                                        <value-of select="$firstline"/>
                                                                                                </otherwise>
                                                                                        </choose>
                                                                                                        <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
                                                                                                </when>
                                                                                                <otherwise>
                                                                                                        <value-of select="$firstline"/>
                                                                                                </otherwise>
                                                                                        </choose>
-                                                                                       <for-each select="following-sibling::*[starts-with(., ' ') and not(preceding-sibling::*[generate-id()=generate-id($next)])]">
+                                                                                       <for-each select="exslset:leading($following, $next)[contains(' &#x9;', substring(., 1, 1))]">
                                                                                                <variable name="nextline" select="normalize-space(.)"/>
                                                                                                <choose>
                                                                                                <variable name="nextline" select="normalize-space(.)"/>
                                                                                                <choose>
-                                                                                                       <when test="substring($nextline, string-length($nextline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
+                                                                                                       <when test="substring($nextline, string-length($nextline))='\' and exslset:intersection($fields, following-sibling::*)[position()=1 and contains(' &#x9;', substring(., 1, 1))]">
                                                                                                                <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
                                                                                                        </when>
                                                                                                        <otherwise>
                                                                                                                <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
                                                                                                        </when>
                                                                                                        <otherwise>
@@ -74,12 +79,12 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                                                        </otherwise>
                                                                                                </choose>
                                                                                        </for-each>
                                                                                                        </otherwise>
                                                                                                </choose>
                                                                                        </for-each>
-                                                                               </html:dd>
-                                                                       </html:div>
+                                                                               </element>
+                                                                       </element>
                                                                </otherwise>
                                                        </choose>
                                                </for-each>
                                                                </otherwise>
                                                        </choose>
                                                </for-each>
-                                       </html:dl>
+                                       </element>
                                </if>
                                <if test="substring-after(., '%%')!=''">
                                        <comment>
                                </if>
                                <if test="substring-after(., '%%')!=''">
                                        <comment>
@@ -87,6 +92,6 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                        </comment>
                                </if>
                        </for-each>
                                        </comment>
                                </if>
                        </for-each>
-               </html:div>
+               </element>
        </template>
 </transform>
        </template>
 </transform>
This page took 0.258239 seconds and 4 git commands to generate.