]> Lady’s Gitweb - Shushe/blobdiff - parsers/record-jar.xslt
Add a basic record-jar parser
[Shushe] / parsers / record-jar.xslt
diff --git a/parsers/record-jar.xslt b/parsers/record-jar.xslt
new file mode 100644 (file)
index 0000000..db8948e
--- /dev/null
@@ -0,0 +1,78 @@
+<?xml version="1.0"?>
+<!--
+⁌ ⛩️📰 书社 ∷ parsers/record-jar.xslt
+
+© 2024 Lady [@ Lady’s 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/>.
+-->
+<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:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
+       exclude-result-prefixes="exsl exslstr"
+       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 class="record-jar">
+                       <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>
+                                               <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>
+                                                                                       <value-of select="normalize-space(substring-before(., ':'))"/>
+                                                                               </html:dt>
+                                                                               <html:dd>
+                                                                                       <variable name="firstline">
+                                                                                               <choose>
+                                                                                                       <when test="contains(., ':')">
+                                                                                                               <value-of select="normalize-space(substring-after(., ':'))"/>
+                                                                                                       </when>
+                                                                                                       <otherwise>
+                                                                                                               <value-of select="normalize-space(.)"/>
+                                                                                                       </otherwise>
+                                                                                               </choose>
+                                                                                       </variable>
+                                                                                       <choose>
+                                                                                               <when test="substring($firstline, string-length($firstline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
+                                                                                                       <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)])]">
+                                                                                               <variable name="nextline" select="normalize-space(.)"/>
+                                                                                               <choose>
+                                                                                                       <when test="substring($nextline, string-length($nextline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
+                                                                                                               <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
+                                                                                                       </when>
+                                                                                                       <otherwise>
+                                                                                                               <value-of select="$nextline"/>
+                                                                                                       </otherwise>
+                                                                                               </choose>
+                                                                                       </for-each>
+                                                                               </html:dd>
+                                                                       </html:div>
+                                                               </otherwise>
+                                                       </choose>
+                                               </for-each>
+                                       </html:dl>
+                               </if>
+                       </for-each>
+               </html:div>
+       </template>
+</transform>
This page took 0.210407 seconds and 4 git commands to generate.