changeset 34:93fd0d532754

fix bug in refs wrt e.g. [1]!.SGX, adapt html and ascii to new-format refs, move a2n and n2a into separate files for re-use
author Henry S. Thompson <ht@markup.co.uk>
date Wed, 12 Apr 2017 21:35:04 +0100
parents 27bffc66ce10
children e500d7c18aad
files a2n.xsl ascii.xsl html.xsl n2a.xsl rect.xsl refs.xsl
diffstat 6 files changed, 61 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/a2n.xsl	Wed Apr 12 21:35:04 2017 +0100
@@ -0,0 +1,13 @@
+<?xml version='1.0'?>
+<!DOCTYPE xsl:stylesheet SYSTEM "file:///C:/C64/home/ht/lib/xml/xsl.dtd" >
+<xsl:stylesheet xmlns:e="http://markup.co.uk/excel" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="3.0">
+  <xsl:function name="e:a2n" as="xs:integer">
+  <!-- Convert an alphabetic excel column 'index' into a number,
+       a sort of base 26 + 1, since 'A' is 1 and 'AA' is 27 -->
+  <xsl:param name="aa" as="xs:string"/>
+  <xsl:value-of select="let $l := string-length($aa),
+                        $lv := string-to-codepoints(substring($aa,$l))-$codeBase
+                        return if ($l=1) then $lv
+                               else $lv+(26*e:a2n(substring($aa,1,$l - 1)))"/>
+ </xsl:function>
+</xsl:stylesheet>
--- a/ascii.xsl	Wed Apr 12 17:43:54 2017 +0100
+++ b/ascii.xsl	Wed Apr 12 21:35:04 2017 +0100
@@ -17,11 +17,12 @@
  </xsl:template>
  
  <xsl:template match="e:c">
-  <xsl:value-of select="if (text())
-                        then 
+  <xsl:value-of select="if (e:t)
+                        then
+                          let $v := if (e:t/@c) then e:t/@c else e:t return 
                           if (@f)
-                          then translate(.,'cdens','CDENS')
-                          else .
+                          then translate($v,'cdens','CDENS')
+                          else $v
                         else ' '"/>
  </xsl:template>
 </xsl:stylesheet>
--- a/html.xsl	Wed Apr 12 17:43:54 2017 +0100
+++ b/html.xsl	Wed Apr 12 21:35:04 2017 +0100
@@ -4,15 +4,20 @@
  <xsl:strip-space elements="e:a"/>
  <xsl:output omit-xml-declaration="yes"/>
  
+ <xsl:include href="n2a.xsl"/>
+
  <xsl:template match="/">
   <html>
    <head>
+    <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
     <style>
        body {font-family: 'DejaVu Sans Mono' , monospace}
        td {padding: 0}
        .e {color: red}
        .formula {font-style: italic}
        .reffed {border: solid 1px black}
+       table {table-layout: fixed}
+       th {width: 1en}
     </style>
    </head>
    <body>
@@ -22,8 +27,15 @@
  </xsl:template>
 
  <xsl:template match="e:a">
+  <xsl:variable name="n" select="count(e:r[1]/e:c)"/>
   <table>
-   <thead/>
+   <thead>
+   <tr>
+    <xsl:for-each select="1 to $n">
+     <th/>
+    </xsl:for-each>
+   </tr>
+   </thead>
    <tbody><xsl:apply-templates/></tbody>
   </table>
  </xsl:template>
@@ -36,15 +48,15 @@
  <xsl:template match="e:c">
   <td>
    <xsl:choose>
-    <xsl:when test="text()">
+    <xsl:when test="e:t">
      <xsl:attribute name="class">
-      <xsl:value-of select="(.,
+      <xsl:value-of select="(e:t,
                              if (@f) then 'formula' else (),
-                             if (@r) then 'reffed' else ())"/>
+                             if (e:r) then 'reffed' else ())"/>
      </xsl:attribute>
-     <xsl:if test="@r"><xsl:attribute name="title"><xsl:value-of select="@r"/></xsl:attribute></xsl:if>
-     <xsl:value-of select="."/></xsl:when>
-    <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
+     <xsl:attribute name="title"><xsl:value-of select="e:n2a(@c)"/><xsl:value-of select="../@r"/><xsl:if test="e:r">: <xsl:value-of select="e:r"/></xsl:if></xsl:attribute>
+     <xsl:value-of select="if (e:t/@c) then e:t/@c else e:t"/></xsl:when>
+    <xsl:otherwise></xsl:otherwise>
    </xsl:choose>
    </td>
  </xsl:template>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/n2a.xsl	Wed Apr 12 21:35:04 2017 +0100
@@ -0,0 +1,19 @@
+<?xml version='1.0'?>
+<!DOCTYPE xsl:stylesheet SYSTEM "file:///C:/C64/home/ht/lib/xml/xsl.dtd" >
+<xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:e="http://markup.co.uk/excel" version="3.0">
+ <xsl:variable name="codeBase" select="string-to-codepoints('A')-1"/>
+ 
+ <xsl:function name="e:n2aa" as="xs:integer*">
+  <!-- Does the real work for e:n2a -->
+  <xsl:param name="n" as="xs:integer"/>
+  <xsl:sequence select="let $least := $codeBase+(($n - 1) mod 26)+1
+                         return if ($n &lt; 27) then $least
+                          else (e:n2aa($n idiv 26),$least)"/>
+ </xsl:function>
+
+ <xsl:function name="e:n2a" as="xs:string">
+  <!-- Invert the a2n computation -->
+  <xsl:param name="n" as="xs:integer"/>
+  <xsl:value-of select="codepoints-to-string(e:n2aa($n))"/>
+ </xsl:function>
+</xsl:stylesheet>
--- a/rect.xsl	Wed Apr 12 17:43:54 2017 +0100
+++ b/rect.xsl	Wed Apr 12 21:35:04 2017 +0100
@@ -3,36 +3,14 @@
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0" xmlns:s="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:e="http://markup.co.uk/excel" exclude-result-prefixes="xs s xpf" xmlns="http://markup.co.uk/excel" xmlns:xpf="http://www.w3.org/2005/xpath-functions">
  <xsl:strip-space elements="s:sheetData"/>
  
+ <xsl:include href="a2n.xsl"/>
+ <xsl:include href="n2a.xsl"/>
+ 
  <xsl:variable name="refs" select="collection()[2]/*"/>
  
  <xsl:key name="ref" match="e:i" use="@r"/>
- 
- <xsl:function name="e:a2n" as="xs:integer">
-  <!-- Convert an alphabetic excel column 'index' into a number,
-       a sort of base 26 + 1, since 'A' is 1 and 'AA' is 27 -->
-  <xsl:param name="aa" as="xs:string"/>
-  <xsl:value-of select="let $l := string-length($aa),
-                        $lv := string-to-codepoints(substring($aa,$l))-$codeBase
-                        return if ($l=1) then $lv
-                               else $lv+(26*e:a2n(substring($aa,1,$l - 1)))"/>
- </xsl:function>
- 
- <xsl:function name="e:n2aa" as="xs:integer*">
-  <!-- Does the real work for e:n2a -->
-  <xsl:param name="n" as="xs:integer"/>
-  <xsl:sequence select="let $least := $codeBase+(($n - 1) mod 26)+1
-                         return if ($n &lt; 27) then $least
-                          else (e:n2aa($n idiv 26),$least)"/>
- </xsl:function>
-
- <xsl:function name="e:n2a" as="xs:string">
-  <!-- Invert the a2n computation -->
-  <xsl:param name="n" as="xs:integer"/>
-  <xsl:value-of select="codepoints-to-string(e:n2aa($n))"/>
- </xsl:function>
 
  <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"/>
--- a/refs.xsl	Wed Apr 12 17:43:54 2017 +0100
+++ b/refs.xsl	Wed Apr 12 21:35:04 2017 +0100
@@ -63,7 +63,7 @@
                              else (),
                   $externals := for $i in (1 to count($tokens)) return
                             let $t := $tokens[$i] return
-                            if ($t/@nr=7)
+                            if ($t/@nr=7 and $tokens[$i+1]='!')
                              then 
                               let $ext := $t!='[0]',
                                   $ref := e:single($tokens[$i + 2],
@@ -118,7 +118,7 @@
  
  <xsl:template match="s:c[s:f]">
   <xsl:variable name="tokens" select="e:tokenise(s:f/.)"/>
-  <xsl:if test="@r='xxx'"><xsl:message>|</xsl:message>
+  <xsl:if test="@r='xxx'"><xsl:message><xsl:value-of select="s:f"/>|<xsl:value-of select="(analyze-string(s:f/.,$pat)/xf:match/xf:group)[3]/@nr"/></xsl:message>
   </xsl:if>
   <xsl:if test="count($tokens)>0">
    <xsl:variable name="singles" select="$tokens?1"/>