annotate n2a.xsl @ 52:9bb415e0adc9

try to fix error processin odd REUTER|IDN\!'.SPX' external ref
author Henry S. Thompson <ht@markup.co.uk>
date Tue, 16 May 2017 17:28:52 +0100
parents d3569a8cbf7a
children adeb9575b273
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
1 <?xml version='1.0'?>
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
2 <!DOCTYPE xsl:stylesheet SYSTEM "file:///C:/C64/home/ht/lib/xml/xsl.dtd" >
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
3 <xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:e="http://markup.co.uk/excel" version="3.0">
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
4 <xsl:variable name="codeBase" select="string-to-codepoints('A')-1"/>
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
5
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
6 <xsl:function name="e:n2aa" as="xs:integer*">
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
7 <!-- Does the real work for e:n2a -->
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
8 <xsl:param name="n" as="xs:integer"/>
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
9 <xsl:sequence select="let $least := $codeBase+(($n - 1) mod 26)+1
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
10 return if ($n &lt; 27) then $least
43
5469a32795da fix off-by-one error
Henry S. Thompson <ht@markup.co.uk>
parents: 34
diff changeset
11 else (e:n2aa(($n - 1) idiv 26),$least)"/>
34
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
12 </xsl:function>
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
13
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
14 <xsl:function name="e:n2a" as="xs:string">
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
15 <!-- Invert the a2n computation -->
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
16 <xsl:param name="n" as="xs:integer"/>
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
17 <xsl:value-of select="codepoints-to-string(e:n2aa($n))"/>
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
18 </xsl:function>
45
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
19
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
20 <xsl:function name="e:crnf" as="xs:string">
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
21 <!-- compute CR-normal-form of a singleton reference -->
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
22 <xsl:param name="s" as="element(e:s)"/>
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
23 <xsl:value-of select="concat(e:snf(($s/*)[1]),e:snf(($s/*)[2]))"/>
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
24 </xsl:function>
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
25
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
26 <xsl:function name="e:snf" as="xs:string">
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
27 <xsl:param name="s" as="element(*)"/><!-- either a(bsolute) or r(elative)-->
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
28 <xsl:value-of select="if (local-name($s)='a')
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
29 then concat('&#xAA;',$s)
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
30 else concat('&#xBA;',$s/@d)"/>
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
31 </xsl:function>
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
32
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
33 <xsl:function name="e:rnf" as="xs:string">
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
34 <!-- CRNF for a range or singleton reference -->
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
35 <xsl:param name="b" as="element(*)"/>
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
36 <xsl:value-of select="if (local-name($b)='s') then e:crnf($b)
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
37 else if (local-name($b)='r')
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
38 then
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
39 let $l := ($b/e:s)[1],
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
40 $r := ($b/e:s)[2] return
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
41 concat(e:crnf($l),
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
42 ':',
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
43 e:crnf($r))
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
44 else if (local-name($b)='v')
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
45 then $b/text()
52
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 49
diff changeset
46 else e:shouldnt('rnf',concat(local-name($b),' ',string($b)))"/>
45
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
47 </xsl:function>
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
48
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
49 <xsl:function name="e:fnf" as="xs:string">
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
50 <!-- rebuild a formula from its parts, but using CRNF for all references -->
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
51 <xsl:param name="bits" as="element(*)*"/>
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
52 <xsl:value-of select="string-join(
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
53 for $b in $bits return
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
54 if (local-name($b)=('s','r')) then e:rnf($b)
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
55 else if (local-name($b)='e')
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
56 then concat($b/@x,'!',e:rnf($b/*))
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
57 else $b/text())"/>
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
58 </xsl:function>
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
59
49
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
60 <xsl:template name="shift">
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
61 <xsl:param name="row" as="xs:integer"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
62 <xsl:param name="col" as="xs:integer"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
63 <!-- Reconstruct a shifted version of an analysed formula, relative to a new position -->
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
64 <xsl:copy>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
65 <xsl:apply-templates select="@*"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
66 <xsl:apply-templates select="*" mode="shift">
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
67 <xsl:with-param name="row" select="$row"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
68 <xsl:with-param name="col" select="$col"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
69 </xsl:apply-templates>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
70 </xsl:copy>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
71 </xsl:template>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
72
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
73 <xsl:template match="e:s" mode="shift">
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
74 <xsl:param name="row" as="xs:integer"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
75 <xsl:param name="col" as="xs:integer"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
76 <xsl:copy>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
77 <xsl:attribute name="r">
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
78 <xsl:value-of select="concat(e:n2a(e:delta(*[1],$col)),
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
79 e:delta(*[2],$row))"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
80 </xsl:attribute>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
81 <xsl:apply-templates select="node()" mode="shift">
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
82 <xsl:with-param name="row" select="$row"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
83 <xsl:with-param name="col" select="$col"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
84 </xsl:apply-templates>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
85 </xsl:copy>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
86 </xsl:template>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
87
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
88 <xsl:function name="e:delta" as="xs:integer">
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
89 <xsl:param name="c" as="element(*)"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
90 <xsl:param name="h" as="xs:integer"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
91 <xsl:value-of select="if (local-name($c)='a') then xs:integer($c/text())
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
92 else if (local-name($c)='r')
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
93 then xs:integer($c/@d)+$h
52
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 49
diff changeset
94 else e:shouldnt('delta',local-name($c))"/>
49
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
95 </xsl:function>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
96
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
97 <xsl:template match="e:*|@*" mode="shift">
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
98 <xsl:param name="row" as="xs:integer"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
99 <xsl:param name="col" as="xs:integer"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
100 <xsl:copy>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
101 <xsl:apply-templates select="node()|@*" mode="shift">
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
102 <xsl:with-param name="row" select="$row"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
103 <xsl:with-param name="col" select="$col"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
104 </xsl:apply-templates>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
105 </xsl:copy>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
106 </xsl:template>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
107
45
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
108 <xsl:function name="e:shouldnt">
52
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 49
diff changeset
109 <xsl:param name="where" as="xs:string"/>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 49
diff changeset
110 <xsl:param name="what" as="xs:string"/>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 49
diff changeset
111 <xsl:message terminate="yes">shouldn't happen in <xsl:value-of select="$where"/>: <xsl:value-of select="$what"/></xsl:message>
45
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
112 </xsl:function>
34
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
113 </xsl:stylesheet>