diff rect.xsl @ 16:2bbd067529b6

improve efficiency, detect blank rows, don't type empty cells
author Henry S. Thompson <ht@markup.co.uk>
date Mon, 03 Apr 2017 19:22:03 +0100
parents f78e8c55c06b
children 9b1b169dc8db
line wrap: on
line diff
--- a/rect.xsl	Mon Apr 03 16:02:10 2017 +0100
+++ b/rect.xsl	Mon Apr 03 19:22:03 2017 +0100
@@ -29,6 +29,10 @@
 
  <xsl:variable name="dim" select="//s:dimension/@ref"/>
  <xsl:variable name="codeBase" select="string-to-codepoints('A')-1"/>
+ 
+ <xsl:template match="/">
+  <xsl:apply-templates select="//s:sheetData"/>
+ </xsl:template>
 
  <xsl:template match="s:sheetData">
   <xsl:if test="s:row">
@@ -41,15 +45,17 @@
     <xsl:text>&#10;</xsl:text>
     <xsl:for-each select="(1 to $height)"><xsl:variable name="row" select="."/>
      <e:r r="{$row}">
-      <xsl:for-each select="(1 to $width)">
+      <xsl:variable select="$sheet/s:row[@r=$row]/s:c" name="cells"/>
+      <xsl:if test="$cells/*">
+       <xsl:for-each select="(1 to $width)">
        <xsl:variable name="col" select="."/>
        <xsl:variable name="r" select="concat(e:n2a($col),string($row))"/>
-       <xsl:variable name="c" select="$sheet/s:row/s:c[@r=$r]"/>
+       <xsl:variable name="c" select="$cells[@r=$r]"/>
        <e:c c="{$col}">
         <xsl:if test="$c/s:f"><xsl:attribute name="f">1</xsl:attribute></xsl:if>
-        <xsl:if test="$c"><xsl:value-of select="substring($c/@e:type,1,1)"/></xsl:if>
+        <xsl:if test="$c/*"><xsl:value-of select="substring($c/@e:type,1,1)"/></xsl:if>
        </e:c>
-      </xsl:for-each>
+      </xsl:for-each></xsl:if>
      </e:r>
      <xsl:text>&#10;</xsl:text></xsl:for-each>
    </e:a>