diff format.xsl @ 7:fd8678fb7b4d

move to type/[class|code]
author Henry S. Thompson <ht@markup.co.uk>
date Sun, 02 Apr 2017 18:18:27 +0800
parents d6dae580f6a0
children 5f2d691014ff
line wrap: on
line diff
--- a/format.xsl	Sun Apr 02 16:49:48 2017 +0800
+++ b/format.xsl	Sun Apr 02 18:18:27 2017 +0800
@@ -15,10 +15,30 @@
  </xsl:function>
 
  <xsl:template match="s:worksheet">
+  <!-- Just here to bind the namespaces at the top -->
   <worksheet xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"><xsl:apply-templates select="@*|node()"/></worksheet>
  </xsl:template>
- <xsl:template match="s:c">
-  <xsl:if test="@s">
+ 
+ <xsl:template match="s:c[@t and @t!='n']">
+  <!-- These take precedence over formatting-->
+  <xsl:copy>
+   <xsl:attribute namespace="http://markup.co.uk/excel" name="type">
+    <xsl:choose>
+     <xsl:when test="@t='s'">str</xsl:when>
+     <xsl:when test="@t='b'">bool</xsl:when><!-- not yet seen -->
+     <xsl:when test="@t='d'">date</xsl:when><!-- not yet seen -->
+     <xsl:when test="@t='e'">err</xsl:when><!-- not yet seen -->
+     <xsl:when test="@t='inlineStr'">str</xsl:when><!-- not yet seen -->
+     <xsl:when test="@t='str'">str</xsl:when><!-- result of formula with string value -->
+     <xsl:otherwise><xsl:message terminate="yes">Unknown value for c/@t <xsl:value-of select="@t"/></xsl:message></xsl:otherwise>
+    </xsl:choose>
+   </xsl:attribute>
+   <xsl:apply-templates select="@*|node()"/>
+  </xsl:copy>
+ </xsl:template>
+ 
+ <xsl:template match="s:c[not(@t) or @t='n']">
+  <!-- I _think_ this can only happen if the contents are in some sense numeric -->
    <xsl:variable name="i" select="number(@s)"/>
    <xsl:variable name="nfi" select="$xfs[position()-1=$i]/@numFmtId"/>
    <xsl:variable name="builtin" select="$fmts[@i=$nfi]"/>
@@ -26,15 +46,26 @@
    <c>
     <xsl:choose>
       <xsl:when test="$biClass">
-       <xsl:attribute namespace="http://markup.co.uk/excel" name="fClass">
+       <xsl:choose>
+        <xsl:when test="$biClass='date'">
+         <xsl:attribute namespace="http://markup.co.uk/excel" name="type">date</xsl:attribute>
+        </xsl:when>
+        <xsl:otherwise>
+         <xsl:attribute namespace="http://markup.co.uk/excel" name="type">num</xsl:attribute>
+         <xsl:if test="$biClass!='num'"><xsl:attribute namespace="http://markup.co.uk/excel" name="class">
         <xsl:value-of select="$biClass"/>
-       </xsl:attribute>
+       </xsl:attribute></xsl:if>
+        </xsl:otherwise>
+       </xsl:choose>
       </xsl:when>
-     <xsl:when test="$nfs[@numFmtId=$nfi]">
+     <xsl:otherwise>
+      <!-- Note the completely vanilla no @t no @s case comes here.  I _think_ it's correct to treat that as numeric -->
+      <xsl:attribute namespace="http://markup.co.uk/excel" name="type">num</xsl:attribute><!-- Would be wrong if any non-numeric formatCodes exist -->
+      <xsl:if test="$nfs[@numFmtId=$nfi]">
       <xsl:variable name="code" select="$nfs[@numFmtId=$nfi]/@formatCode"/>
       <xsl:choose>
        <xsl:when test="e:currencyFormatP($code)">
-        <xsl:attribute namespace="http://markup.co.uk/excel" name="fClass">cur</xsl:attribute>
+        <xsl:attribute namespace="http://markup.co.uk/excel" name="class">cur</xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
         <xsl:attribute namespace="http://markup.co.uk/excel" name="code">
@@ -42,12 +73,12 @@
       </xsl:attribute>
        </xsl:otherwise>
       </xsl:choose>
-     </xsl:when>
+     </xsl:if>
+     </xsl:otherwise>
     </xsl:choose>
     <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>
     <xsl:apply-templates/>
-   </c>
-  </xsl:if>
+   </c>  
  </xsl:template>
  <xsl:template match="@*|node()"><xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
  </xsl:template>