annotate a2n.xsl @ 57:a783afa2b109

much richer annotatation as json-formatted comment
author Henry S. Thompson <ht@markup.co.uk>
date Wed, 31 May 2017 17:41:18 +0100
parents 5d9806f90896
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" >
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
48
5d9806f90896 basic integration of shared, but copying <f> is wrong, should reconstruct by denormalising <nf> for new home
Henry S. Thompson <ht@markup.co.uk>
parents: 36
diff changeset
16 <xsl:function name="e:pr" as="element(xpf:analyze-string-result)">
5d9806f90896 basic integration of shared, but copying <f> is wrong, should reconstruct by denormalising <nf> for new home
Henry S. Thompson <ht@markup.co.uk>
parents: 36
diff changeset
17 <xsl:param name="ref" as="xs:string"/>
5d9806f90896 basic integration of shared, but copying <f> is wrong, should reconstruct by denormalising <nf> for new home
Henry S. Thompson <ht@markup.co.uk>
parents: 36
diff changeset
18 <xsl:sequence select="analyze-string($ref,'([$]?)([A-Z]+)([$]?)([0-9]+)')"/>
5d9806f90896 basic integration of shared, but copying <f> is wrong, should reconstruct by denormalising <nf> for new home
Henry S. Thompson <ht@markup.co.uk>
parents: 36
diff changeset
19 </xsl:function>
5d9806f90896 basic integration of shared, but copying <f> is wrong, should reconstruct by denormalising <nf> for new home
Henry S. Thompson <ht@markup.co.uk>
parents: 36
diff changeset
20
36
ae605b77d1e4 compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents: 34
diff changeset
21 <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
22 <!-- 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
23 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
24 <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
25 <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
26 <xsl:param name="col" as="xs:integer" required="yes"/>
48
5d9806f90896 basic integration of shared, but copying <f> is wrong, should reconstruct by denormalising <nf> for new home
Henry S. Thompson <ht@markup.co.uk>
parents: 36
diff changeset
27 <xsl:variable name="cr" select="e:pr($ref)"/>
36
ae605b77d1e4 compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents: 34
diff changeset
28 <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
29 <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
30 <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
31 <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
32 <s r="{$ref}">
ae605b77d1e4 compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents: 34
diff changeset
33 <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
34 <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
35 <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
36 </xsl:if>
ae605b77d1e4 compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents: 34
diff changeset
37 <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
38 </xsl:element>
ae605b77d1e4 compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents: 34
diff changeset
39 <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
40 <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
41 <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
42 </xsl:if>
ae605b77d1e4 compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents: 34
diff changeset
43 <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
44 </xsl:element>
ae605b77d1e4 compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents: 34
diff changeset
45 </s>
ae605b77d1e4 compute (but not use) master formula cells info,
Henry S. Thompson <ht@markup.co.uk>
parents: 34
diff changeset
46 </xsl:function>
34
93fd0d532754 fix bug in refs wrt e.g. [1]!.SGX,
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
47 </xsl:stylesheet>