annotate n2a.xsl @ 66:d0edaceb04b6

first time to Sonra, Kostas
author Henry S. Thompson <ht@markup.co.uk>
date Mon, 12 Jun 2017 17:08:07 +0200
parents adeb9575b273
children
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>
58
adeb9575b273 add inverted rel pointers back to referencing from referenced
Henry S. Thompson <ht@markup.co.uk>
parents: 52
diff changeset
48
adeb9575b273 add inverted rel pointers back to referencing from referenced
Henry S. Thompson <ht@markup.co.uk>
parents: 52
diff changeset
49 <xsl:function name="e:bcrnf" as="xs:string">
adeb9575b273 add inverted rel pointers back to referencing from referenced
Henry S. Thompson <ht@markup.co.uk>
parents: 52
diff changeset
50 <!-- Like crnf, but backpointer -->
adeb9575b273 add inverted rel pointers back to referencing from referenced
Henry S. Thompson <ht@markup.co.uk>
parents: 52
diff changeset
51 <!-- compute CR-normal-form of a singleton reference -->
adeb9575b273 add inverted rel pointers back to referencing from referenced
Henry S. Thompson <ht@markup.co.uk>
parents: 52
diff changeset
52 <xsl:param name="s" as="element(e:s)"/>
adeb9575b273 add inverted rel pointers back to referencing from referenced
Henry S. Thompson <ht@markup.co.uk>
parents: 52
diff changeset
53 <xsl:value-of select="concat(e:bnf(($s/*)[1]),e:bnf(($s/*)[2]))"/>
adeb9575b273 add inverted rel pointers back to referencing from referenced
Henry S. Thompson <ht@markup.co.uk>
parents: 52
diff changeset
54 </xsl:function>
adeb9575b273 add inverted rel pointers back to referencing from referenced
Henry S. Thompson <ht@markup.co.uk>
parents: 52
diff changeset
55
adeb9575b273 add inverted rel pointers back to referencing from referenced
Henry S. Thompson <ht@markup.co.uk>
parents: 52
diff changeset
56 <xsl:function name="e:bnf" as="xs:string">
adeb9575b273 add inverted rel pointers back to referencing from referenced
Henry S. Thompson <ht@markup.co.uk>
parents: 52
diff changeset
57 <!-- invert any relative references, neutralise any absolute ones, i.e. convert a pointer into a kind of backpointer -->
adeb9575b273 add inverted rel pointers back to referencing from referenced
Henry S. Thompson <ht@markup.co.uk>
parents: 52
diff changeset
58 <xsl:param name="s" as="element(*)"/><!-- either a(bsolute) or r(elative)-->
adeb9575b273 add inverted rel pointers back to referencing from referenced
Henry S. Thompson <ht@markup.co.uk>
parents: 52
diff changeset
59 <xsl:value-of select="if (local-name($s)='a')
adeb9575b273 add inverted rel pointers back to referencing from referenced
Henry S. Thompson <ht@markup.co.uk>
parents: 52
diff changeset
60 then concat('&#xAA;',$s) (: avoid spurious concord :)
adeb9575b273 add inverted rel pointers back to referencing from referenced
Henry S. Thompson <ht@markup.co.uk>
parents: 52
diff changeset
61 else concat('&#xBA;',-xs:integer($s/@d))"/>
adeb9575b273 add inverted rel pointers back to referencing from referenced
Henry S. Thompson <ht@markup.co.uk>
parents: 52
diff changeset
62 </xsl:function>
adeb9575b273 add inverted rel pointers back to referencing from referenced
Henry S. Thompson <ht@markup.co.uk>
parents: 52
diff changeset
63
45
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
64
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
65 <xsl:function name="e:fnf" as="xs:string">
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
66 <!-- 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
67 <xsl:param name="bits" as="element(*)*"/>
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
68 <xsl:value-of select="string-join(
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
69 for $b in $bits return
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
70 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
71 else if (local-name($b)='e')
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
72 then concat($b/@x,'!',e:rnf($b/*))
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
73 else $b/text())"/>
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
74 </xsl:function>
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
75
49
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
76 <xsl:template name="shift">
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
77 <xsl:param name="row" as="xs:integer"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
78 <xsl:param name="col" as="xs:integer"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
79 <!-- 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
80 <xsl:copy>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
81 <xsl:apply-templates select="@*"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
82 <xsl:apply-templates select="*" mode="shift">
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
83 <xsl:with-param name="row" select="$row"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
84 <xsl:with-param name="col" select="$col"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
85 </xsl:apply-templates>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
86 </xsl:copy>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
87 </xsl:template>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
88
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
89 <xsl:template match="e:s" mode="shift">
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
90 <xsl:param name="row" as="xs:integer"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
91 <xsl:param name="col" as="xs:integer"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
92 <xsl:copy>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
93 <xsl:attribute name="r">
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
94 <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
95 e:delta(*[2],$row))"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
96 </xsl:attribute>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
97 <xsl:apply-templates select="node()" mode="shift">
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
98 <xsl:with-param name="row" select="$row"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
99 <xsl:with-param name="col" select="$col"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
100 </xsl:apply-templates>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
101 </xsl:copy>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
102 </xsl:template>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
103
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
104 <xsl:function name="e:delta" as="xs:integer">
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
105 <xsl:param name="c" as="element(*)"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
106 <xsl:param name="h" as="xs:integer"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
107 <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
108 else if (local-name($c)='r')
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
109 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
110 else e:shouldnt('delta',local-name($c))"/>
49
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
111 </xsl:function>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
112
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
113 <xsl:template match="e:*|@*" mode="shift">
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
114 <xsl:param name="row" as="xs:integer"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
115 <xsl:param name="col" as="xs:integer"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
116 <xsl:copy>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
117 <xsl:apply-templates select="node()|@*" mode="shift">
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
118 <xsl:with-param name="row" select="$row"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
119 <xsl:with-param name="col" select="$col"/>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
120 </xsl:apply-templates>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
121 </xsl:copy>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
122 </xsl:template>
d3569a8cbf7a shared refs rebuilt correctly
Henry S. Thompson <ht@markup.co.uk>
parents: 45
diff changeset
123
45
6ed900e8cc61 towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents: 43
diff changeset
124 <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
125 <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
126 <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
127 <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
128 </xsl:function>
34
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
129 </xsl:stylesheet>