From: Lady <redacted> Date: Fri, 20 Sep 2024 03:20:43 +0000 (-0400) Subject: Preserve comments in Record‐Jar and T·S·V formats X-Git-Tag: 0.13.0~3 X-Git-Url: https://git.ladys.computer/Shushe/commitdiff_plain/ee9a8dfd2a43ea23ede57da28aebc3c2162edf51?ds=inline;hp=2b85a319534edf60358ac73d57ad0d34b7a6d113 Preserve comments in Record‐Jar and T·S·V formats --- diff --git a/parsers/record-jar.xslt b/parsers/record-jar.xslt index bd04730..abaf08c 100644 --- a/parsers/record-jar.xslt +++ b/parsers/record-jar.xslt @@ -24,6 +24,11 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one <template match="html:script[@type='text/record-jar']"> <variable name="lines" select="exslstr:tokenize(., '
')"/> <html:div> + <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]"/> @@ -76,6 +81,11 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one </for-each> </html:dl> </if> + <if test="substring-after(., '%%')!=''"> + <comment> + <value-of select="substring-after(., '%%')"/> + </comment> + </if> </for-each> </html:div> </template> diff --git a/parsers/tsv.xslt b/parsers/tsv.xslt index 21ad1e0..5b3cc68 100644 --- a/parsers/tsv.xslt +++ b/parsers/tsv.xslt @@ -23,16 +23,20 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one <import href="../lib/split.xslt"/> <书社:id>urn:fdc:ladys.computer:20231231:Shu1She4:tsv.xslt</书社:id> <template match="html:script[@type='text/tab-separated-values']"> - <variable name="rows" select="exslstr:tokenize(., '
')[normalize-space(.)!='' and not(starts-with(., '#'))]"/> - <variable name="head" select="$rows[1]"/> + <variable name="lines" select="exslstr:tokenize(., '
')"/> + <variable name="head" select="$lines[normalize-space(.)!='' and not(starts-with(., '#'))][1]"/> <variable name="headcols"> <call-template name="书社:split"> <with-param name="source" select="string($head)"/> <with-param name="separator" select="'	'"/> </call-template> </variable> - <variable name="body" select="$rows[not(position()=1)]"/> <html:table> + <for-each select="$lines[starts-with(., '#') and following-sibling::*[generate-id(.)=generate-id($head)]]"> + <comment> + <value-of select="substring-after(., '#')"/> + </comment> + </for-each> <html:thead> <html:tr> <for-each select="exsl:node-set($headcols)/*"> @@ -43,32 +47,41 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one </html:tr> </html:thead> <html:tbody> - <for-each select="$body"> - <variable name="cols"> - <call-template name="书社:split"> - <with-param name="source" select="string(.)"/> - <with-param name="separator" select="'	'"/> - </call-template> - </variable> - <html:tr> - <for-each select="exsl:node-set($cols)/*[count(exsl:node-set($headcols)/*)>=position()]"> - <html:td> - <attribute name="data-tsv-header"> - <value-of select="exsl:node-set($headcols)/*[count(current()/preceding-sibling::*)+1]"/> - </attribute> - <value-of select="."/> - <if test="position()=count(exsl:node-set($headcols)/*)"> - <for-each select="following-sibling::*"> - <text>	</text> + <for-each select="$head/following-sibling::*[normalize-space(.)!='']"> + <choose> + <when test="starts-with(., '#')"> + <comment> + <value-of select="substring-after(., '#')"/> + </comment> + </when> + <otherwise> + <variable name="cols"> + <call-template name="书社:split"> + <with-param name="source" select="string(.)"/> + <with-param name="separator" select="'	'"/> + </call-template> + </variable> + <html:tr> + <for-each select="exsl:node-set($cols)/*[count(exsl:node-set($headcols)/*)>=position()]"> + <html:td> + <attribute name="data-tsv-header"> + <value-of select="exsl:node-set($headcols)/*[count(current()/preceding-sibling::*)+1]"/> + </attribute> <value-of select="."/> - </for-each> - </if> - </html:td> - </for-each> - <for-each select="exsl:node-set($headcols)/*[position()>count(exsl:node-set($cols)/*)]"> - <html:td/> - </for-each> - </html:tr> + <if test="position()=count(exsl:node-set($headcols)/*)"> + <for-each select="following-sibling::*"> + <text>	</text> + <value-of select="."/> + </for-each> + </if> + </html:td> + </for-each> + <for-each select="exsl:node-set($headcols)/*[position()>count(exsl:node-set($cols)/*)]"> + <html:td/> + </for-each> + </html:tr> + </otherwise> + </choose> </for-each> </html:tbody> </html:table>