Mercurial > hg > ooxml
annotate n2a.xsl @ 45:6ed900e8cc61
towards comparable formulae
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Sun, 07 May 2017 19:21:53 +0100 |
parents | 5469a32795da |
children | d3569a8cbf7a |
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 < 27) then $least |
43 | 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('ª',$s) |
6ed900e8cc61
towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents:
43
diff
changeset
|
30 else concat('º',$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() |
6ed900e8cc61
towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents:
43
diff
changeset
|
46 else e:shouldnt()"/> |
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 |
6ed900e8cc61
towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents:
43
diff
changeset
|
60 <xsl:function name="e:shouldnt"> |
6ed900e8cc61
towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents:
43
diff
changeset
|
61 <xsl:message terminate="yes">shouldn't happen</xsl:message> |
6ed900e8cc61
towards comparable formulae
Henry S. Thompson <ht@markup.co.uk>
parents:
43
diff
changeset
|
62 </xsl:function> |
34
93fd0d532754
fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
63 </xsl:stylesheet> |