changeset 45:6ed900e8cc61

towards comparable formulae
author Henry S. Thompson <ht@markup.co.uk>
date Sun, 07 May 2017 19:21:53 +0100
parents 5b2333e59d91
children 8dd54346bfd8
files merge.xsl n2a.xsl notes.txt refs.xsl
diffstat 4 files changed, 53 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/merge.xsl	Sun May 07 11:56:02 2017 +0100
+++ b/merge.xsl	Sun May 07 19:21:53 2017 +0100
@@ -15,7 +15,10 @@
   <xsl:variable name="col" select="@c"/>
   <xsl:variable name="reffed" select="key('ref',concat(e:n2a($col),$row),$refs)"/>
   <c>
-   <xsl:apply-templates select="node()|@*"/>
+   <xsl:apply-templates select="@*"/>
+   <xsl:if test="e:f">
+    <xsl:attribute name="f"></xsl:attribute>
+   </xsl:if>
   <xsl:if test="$reffed"><xsl:copy-of select="$reffed"/></xsl:if>
   </c>
  </xsl:template>
--- a/n2a.xsl	Sun May 07 11:56:02 2017 +0100
+++ b/n2a.xsl	Sun May 07 19:21:53 2017 +0100
@@ -16,4 +16,48 @@
   <xsl:param name="n" as="xs:integer"/>
   <xsl:value-of select="codepoints-to-string(e:n2aa($n))"/>
  </xsl:function>
+ 
+ <xsl:function name="e:crnf" as="xs:string">
+  <!-- compute CR-normal-form of a singleton reference -->
+  <xsl:param name="s" as="element(e:s)"/>
+  <xsl:value-of select="concat(e:snf(($s/*)[1]),e:snf(($s/*)[2]))"/>
+ </xsl:function>
+ 
+ <xsl:function name="e:snf" as="xs:string">
+  <xsl:param name="s" as="element(*)"/><!-- either a(bsolute) or r(elative)-->
+  <xsl:value-of select="if (local-name($s)='a')
+                         then concat('&#xAA;',$s)
+                         else concat('&#xBA;',$s/@d)"/>
+ </xsl:function>
+ 
+ <xsl:function name="e:rnf" as="xs:string">
+  <!-- CRNF for a range or singleton reference -->
+  <xsl:param name="b" as="element(*)"/>
+  <xsl:value-of select="if (local-name($b)='s') then e:crnf($b)
+                           else if (local-name($b)='r')
+                                 then
+                                  let $l := ($b/e:s)[1],
+                                      $r := ($b/e:s)[2] return
+                                     concat(e:crnf($l),
+                                            ':',
+                                            e:crnf($r))
+                                 else if (local-name($b)='v')
+                                  then $b/text()
+                                 else e:shouldnt()"/>
+ </xsl:function>
+ 
+ <xsl:function name="e:fnf" as="xs:string">
+  <!-- rebuild a formula from its parts, but using CRNF for all references -->
+  <xsl:param name="bits" as="element(*)*"/>
+  <xsl:value-of select="string-join(
+                          for $b in $bits return
+                           if (local-name($b)=('s','r')) then e:rnf($b)
+                           else if (local-name($b)='e')
+                                 then concat($b/@x,'!',e:rnf($b/*))
+                          else $b/text())"/>
+ </xsl:function>
+ 
+ <xsl:function name="e:shouldnt">
+  <xsl:message terminate="yes">shouldn't happen</xsl:message>
+ </xsl:function>
 </xsl:stylesheet>
--- a/notes.txt	Sun May 07 11:56:02 2017 +0100
+++ b/notes.txt	Sun May 07 19:21:53 2017 +0100
@@ -180,7 +180,7 @@
                                         output of format.xsl FIXED
 -----------
 Need to rethink variable handling...
-Is all we really need a normalised formula computation:
+Is all we really need a normalised formula computation?:
  1) recursively replace variables;
  2) convert all simple refs to new CR string normal form: 
     crnf ::= col row
--- a/refs.xsl	Sun May 07 11:56:02 2017 +0100
+++ b/refs.xsl	Sun May 07 19:21:53 2017 +0100
@@ -8,12 +8,14 @@
   <refs><xsl:apply-templates select="//e:c"/></refs>
  </xsl:template>
  
- <xsl:template match="e:c[e:f/(e:s|e:r)]">
+ <xsl:template match="e:c[e:f]">
   <xsl:variable name="r" select="../@r"/>
   <xsl:variable name="c" select="@c"/>
+  <xsl:variable name="i" select="concat(e:n2a($c),$r)"/>
   <xsl:if test="@r='xxx' and @c='1'"><xsl:message><xsl:value-of select="count(e:f/*)"/>|</xsl:message>
   </xsl:if>
-  <ref r="{e:n2a($c)}{$r}"><xsl:apply-templates select="e:f/(e:s|e:r)"/></ref>
+  <nf r="{$i}"><xsl:value-of select="e:fnf(e:f/*)"/></nf>
+  <xsl:if test="e:f[e:s|e:r]"><ref r="{$i}"><xsl:apply-templates select="e:f[e:s|e:r]"/></ref></xsl:if>
  </xsl:template>
  
  <xsl:template match="e:c"/>