]> Lady’s Gitweb - Shushe/blobdiff - parsers/record-jar.xslt
Don’t use literal result elements in parsers
[Shushe] / parsers / record-jar.xslt
index 352951d8828d72ff7cedfc4901f765325c631602..b58505d3600da93e842ae752f1581a4fa30f6cc2 100644 (file)
@@ -6,16 +6,19 @@ SPDX-License-Identifier: MPL-2.0
 <!--
 ⁌ ⛩📰 书社 ∷ parsers/record-jar.xslt
 
-© 2024 Lady [@ Ladys Computer].
+© 2024 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/>.
 -->
+<!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"
        xmlns:exslstr="http://exslt.org/strings"
-       xmlns:html="http://www.w3.org/1999/xhtml"
+       xmlns:html="&xhtml;"
        xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
        extension-element-prefixes="exsl exslstr"
        version="1.0"
@@ -23,23 +26,28 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
        <书社: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>
+               <element name="div" namespace="&xhtml;">
+                       <if test="starts-with($lines[1], '%%') and substring-after($lines[1], '%%')!=''">
+                               <comment>
+                                       <value-of select="substring-after($lines[1], '%%')"/>
+                               </comment>
+                       </if>
                        <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(., '%%'))]"/>
                                <if test="$fields">
-                                       <html:dl>
+                                       <element name="dl" namespace="&xhtml;">
                                                <for-each select="$fields">
                                                        <choose>
                                                                <when test="starts-with(., ' ') and $fields[generate-id()=generate-id(current()/preceding-sibling::*[1])]"/>
                                                                <otherwise>
                                                                        <variable name="next" select="following-sibling::*[not(starts-with(., ' '))]"/>
-                                                                       <html:div>
-                                                                               <html:dt>
+                                                                       <element name="div" namespace="&xhtml;">
+                                                                               <element name="dt" namespace="&xhtml;">
                                                                                        <value-of select="normalize-space(substring-before(., ':'))"/>
-                                                                               </html:dt>
-                                                                               <html:dd>
+                                                                               </element>
+                                                                               <element name="dd" namespace="&xhtml;">
                                                                                        <variable name="firstline">
                                                                                                <choose>
                                                                                                        <when test="contains(., ':')">
@@ -69,14 +77,19 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                                                        </otherwise>
                                                                                                </choose>
                                                                                        </for-each>
-                                                                               </html:dd>
-                                                                       </html:div>
+                                                                               </element>
+                                                                       </element>
                                                                </otherwise>
                                                        </choose>
                                                </for-each>
-                                       </html:dl>
+                                       </element>
+                               </if>
+                               <if test="substring-after(., '%%')!=''">
+                                       <comment>
+                                               <value-of select="substring-after(., '%%')"/>
+                                       </comment>
                                </if>
                        </for-each>
-               </html:div>
+               </element>
        </template>
 </transform>
This page took 0.022225 seconds and 4 git commands to generate.