]> Lady’s Gitweb - Shushe/blobdiff - parsers/tsv.xslt
Improve (fix) the T·S·V parser
[Shushe] / parsers / tsv.xslt
index a3dd9275b8cc42da52fa7a641e2c1b6ab3196f1a..ae721e4e8565424d81df15b6303752d492e620c8 100644 (file)
@@ -16,15 +16,22 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
        exclude-result-prefixes="exsl exslstr"
        version="1.0"
 >
+       <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(., '&#xA;')[normalize-space(.) and not(starts-with(., '#'))]"/>
+               <variable name="rows" select="exslstr:tokenize(., '&#xA;')[normalize-space(.)!='' and not(starts-with(., '#'))]"/>
                <variable name="head" select="$rows[1]"/>
+               <variable name="headcols">
+                       <call-template name="书社:split">
+                               <with-param name="source" select="string($head)"/>
+                               <with-param name="separator" select="'&#x9;'"/>
+                       </call-template>
+               </variable>
                <variable name="body" select="$rows[not(position()=1)]"/>
                <html:table>
                        <html:thead>
                                <html:tr>
-                                       <for-each select="exslstr:tokenize($head, '&#x9;')">
+                                       <for-each select="exsl:node-set($headcols)/*">
                                                <html:th scope="col">
                                                        <value-of select="."/>
                                                </html:th>
@@ -33,12 +40,27 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                        </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="'&#x9;'"/>
+                                               </call-template>
+                                       </variable>
                                        <html:tr>
-                                               <for-each select="exslstr:tokenize(., '&#x9;')">
+                                               <for-each select="exsl:node-set($cols)/*[count(exsl:node-set($headcols)/*)>position()]">
                                                        <html:td>
                                                                <value-of select="."/>
+                                                               <if test="position()=count(exsl:node-set($headcols)/*)">
+                                                                       <for-each select="following-sibling:*">
+                                                                               <text>&#x9;</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>
                                </for-each>
                        </html:tbody>
This page took 0.024665 seconds and 4 git commands to generate.