Mercurial > hg > ooxml
annotate a2n.xsl @ 46:8dd54346bfd8
tabulate unique normalised formulae
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Sun, 07 May 2017 22:03:31 +0100 |
parents | ae605b77d1e4 |
children | 5d9806f90896 |
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" > |
36
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
3 <xsl:stylesheet xmlns:e="http://markup.co.uk/excel" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="3.0" xmlns:xpf="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="e xpf xs" xmlns="http://markup.co.uk/excel"> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
4 |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
5 <xsl:function name="e:a2n" as="xs:integer"> |
34
93fd0d532754
fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
6 <!-- Convert an alphabetic excel column 'index' into a number, |
93fd0d532754
fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
7 a sort of base 26 + 1, since 'A' is 1 and 'AA' is 27 --> |
36
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
8 <xsl:param name="aa" as="xs:string" required="yes"/> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
9 <xsl:variable name="codeBase" select="string-to-codepoints('A')-1"/> |
34
93fd0d532754
fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
10 <xsl:value-of select="let $l := string-length($aa), |
93fd0d532754
fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
11 $lv := string-to-codepoints(substring($aa,$l))-$codeBase |
93fd0d532754
fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
12 return if ($l=1) then $lv |
93fd0d532754
fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
13 else $lv+(26*e:a2n(substring($aa,1,$l - 1)))"/> |
93fd0d532754
fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
14 </xsl:function> |
36
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
15 |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
16 <xsl:function name="e:cr" as="element(e:s)"> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
17 <!-- Parse a single cell reference into left and right halves, |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
18 either e:a(bsolute) or e:r(elocatable) --> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
19 <xsl:param name="ref" as="xs:string" required="yes"/> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
20 <xsl:param name="row" as="xs:integer" required="yes"/> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
21 <xsl:param name="col" as="xs:integer" required="yes"/> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
22 <xsl:variable name="cr" select="analyze-string($ref,'([$]?)([A-Z]+)([$]?)([0-9]+)')"/> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
23 <xsl:variable name="c" select="if ($cr//xpf:group[@nr=1][text()]) then 'a' else 'r'"/> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
24 <xsl:variable name="cv" select="e:a2n($cr//xpf:group[@nr=2])"/> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
25 <xsl:variable name="r" select="if ($cr//xpf:group[@nr=3][text()]) then 'a' else 'r'"/> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
26 <xsl:variable name="rv" select="xs:integer($cr//xpf:group[@nr=4])"/> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
27 <s r="{$ref}"> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
28 <xsl:element name="{$c}" namespace="http://markup.co.uk/excel"> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
29 <xsl:if test="$c='r'"> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
30 <xsl:attribute name="d"><xsl:value-of select="$cv - $col"/></xsl:attribute> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
31 </xsl:if> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
32 <xsl:value-of select="$cv"/> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
33 </xsl:element> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
34 <xsl:element name="{$r}" namespace="http://markup.co.uk/excel"> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
35 <xsl:if test="$r='r'"> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
36 <xsl:attribute name="d"><xsl:value-of select="$rv - $row"/></xsl:attribute> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
37 </xsl:if> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
38 <xsl:value-of select="$rv"/> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
39 </xsl:element> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
40 </s> |
ae605b77d1e4
compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents:
34
diff
changeset
|
41 </xsl:function> |
34
93fd0d532754
fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
42 </xsl:stylesheet> |