Mercurial > hg > ooxml
annotate tokenise.xsl @ 50:01a7c2ebd3d1
top 20 shared formulae coloured in
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Thu, 11 May 2017 09:29:33 +0100 |
parents | ac6d1ca099f7 |
children | 9bb415e0adc9 |
rev | line source |
---|---|
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
1 <?xml version='1.0'?> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
2 <!DOCTYPE xsl:stylesheet SYSTEM "../../../lib/xml/xsl.dtd" > |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
3 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0" xmlns:s="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:e="http://markup.co.uk/excel" exclude-result-prefixes="xs s e xf" xmlns="http://markup.co.uk/excel" xmlns:xf="http://www.w3.org/2005/xpath-functions"> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
4 <xsl:param name="sheet-number"/> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
5 <xsl:param name="xlDir"/> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
6 |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
7 <xsl:variable name="pat1">("[^"]*")|(\{[^}]+})|(,)|([^=\-+*/();:,.$<>^!]+(?:\.[^=\-+*/();:,.$<>^!]+)*\()|([)])|(^=|\()|((?:(?:'[^']+')|(?:\[[0-9]+\][^!]*)|(?:[a-zA-Z_][a-zA-Z0-9._]*)!))|(\$?[A-Z]+\$?[0-9]+)|([a-zA-Z_\\][a-zA-Z0-9._]*)|(.)</xsl:variable> |
39
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
8 <xsl:variable name="pat2">("[^"]*")|(\{[^}]+})|(,)|([^=\-+*/();:,.$<>^!]+(?:\.[^=\-+*/();:,.$<>^!]+)*\()|([)])|(^=|\()|((?:'[^']+'!)|(?:[\[0-9A-Za-z_][^=\-+*/();:,.$<>^!]*!))|(\$?[A-Z]+\$?[0-9]+)|([a-zA-Z_\\][a-zA-Z0-9._]*)|(.)</xsl:variable> |
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
9 <xsl:param name="pat" select="$pat2"/><!-- xsl:param for refinement debugging by passing in the pattern --> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
10 |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
11 <xsl:variable name="workbook" select="document(concat($xlDir,'/workbook.xml'))/*"/> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
12 <xsl:variable name="sheet-name" select="$workbook/s:sheets/s:sheet[@sheetId=$sheet-number]/@name"/> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
13 |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
14 <xsl:function name="e:lookup" as="xs:string*"> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
15 <xsl:param name="name" as="xs:string" required="yes"/> |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
16 <xsl:value-of select="string($workbook/s:definedNames/s:definedName[@name=$name])"/> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
17 </xsl:function> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
18 |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
19 <xsl:function name="e:tokenise" as="element(*)*"> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
20 <!-- Tokenise a formula, recursively wrt variables |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
21 Output is composed of e:* as follows: |
39
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
22 b: Boolean constant |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
23 c: A list (function parameter) separator |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
24 e: An external (variable, cell or range) reference |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
25 l: The beginning of the formula or an opening paren |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
26 m: A constant matrix |
40
ac6d1ca099f7
simplified rect output, refs (not refs2) working again
Henry S. Thompson <ht@markup.co.uk>
parents:
39
diff
changeset
|
27 o: A function name followed by an opening parenthesis |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
28 p: A close-paren |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
29 q: A text (delimited by double quotes) |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
30 r: A range reference (two children, either e or s or u (unsupported)) |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
31 s: A single-cell reference |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
32 v: A variable name [should only occur inside e] |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
33 x: Amalgamated single characters not matched by anything else |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
34 --> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
35 <xsl:param name="formula" as="xs:string" required="yes"/> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
36 <!-- The row and column number of the cell whence the formula came --> |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
37 <xsl:param name="row" required="yes" as="xs:integer"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
38 <xsl:param name="col" required="yes" as="xs:integer"/> |
40
ac6d1ca099f7
simplified rect output, refs (not refs2) working again
Henry S. Thompson <ht@markup.co.uk>
parents:
39
diff
changeset
|
39 <xsl:if test="false()"><xsl:message>tok: <xsl:value-of select="$formula"/></xsl:message></xsl:if> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
40 <xsl:sequence select=" |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
41 let $tokens := analyze-string($formula,$pat)/xf:match/xf:group |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
42 return e:tok1($tokens,count($tokens),1,$row,$col,())"/> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
43 </xsl:function> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
44 |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
45 <xsl:function name="e:tok1" as="element(*)*"> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
46 <xsl:param name="tokens" as="element(xf:group)*" required="yes"/> |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
47 <xsl:param name="n" required="yes" as="xs:integer"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
48 <xsl:param name="i" required="yes" as="xs:integer"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
49 <xsl:param name="row" required="yes" as="xs:integer"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
50 <xsl:param name="col" required="yes" as="xs:integer"/> |
39
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
51 <xsl:param name="soFar" as="element(*)*"/> |
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
52 <xsl:variable name="last" select="$soFar[count($soFar)]"></xsl:variable> |
40
ac6d1ca099f7
simplified rect output, refs (not refs2) working again
Henry S. Thompson <ht@markup.co.uk>
parents:
39
diff
changeset
|
53 <xsl:if test="false()"><xsl:message>tok1: <xsl:value-of select="$n"/>|<xsl:value-of select="$i"/>|<xsl:value-of select="if ($last instance of element()) then name($last) else 'bogus'"/>|<xsl:value-of select="string($last)"/></xsl:message></xsl:if> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
54 <xsl:sequence select=" |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
55 if ($i gt $n) |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
56 then $soFar |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
57 else |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
58 let $next := e:expand($tokens,$i,true(),$row,$col), |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
59 $j := $next?1, |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
60 $res := $next?2 return |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
61 e:tok1($tokens,$n,$j,$row,$col,($soFar,$res))"/> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
62 </xsl:function> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
63 |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
64 <xsl:function name="e:expand" as="array(*)"> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
65 <xsl:param name="tokens" required="yes" as="element(xf:group)*"/> |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
66 <xsl:param name="i" required="yes" as="xs:integer"/> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
67 <xsl:param name="local" required="yes" as="xs:boolean"/> |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
68 <xsl:param name="row" required="yes" as="xs:integer"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
69 <xsl:param name="col" required="yes" as="xs:integer"/> |
40
ac6d1ca099f7
simplified rect output, refs (not refs2) working again
Henry S. Thompson <ht@markup.co.uk>
parents:
39
diff
changeset
|
70 <xsl:if test="false()"><xsl:message>exp: <xsl:value-of select="$tokens[$i]/@nr"/>:<xsl:value-of select="$tokens[$i]"/>,<xsl:value-of select="$tokens[$i+1]"/></xsl:message></xsl:if> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
71 <xsl:sequence select=" |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
72 let $t := $tokens[$i], |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
73 $r := $tokens[$i + 1] return |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
74 if ($t/@nr=1) then e:exp1($i,'q',string($t)) |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
75 else if ($t/@nr=2) then e:exp1($i,'m',string($t)) |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
76 else if ($t/@nr=3) then e:exp1($i,'c',',') |
40
ac6d1ca099f7
simplified rect output, refs (not refs2) working again
Henry S. Thompson <ht@markup.co.uk>
parents:
39
diff
changeset
|
77 else if ($t/@nr=4) then e:exp1($i,'o',string($t)) |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
78 else if ($t/@nr=5) then e:exp1($i,'p',')') |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
79 else if ($t/@nr=6) then e:exp1($i,'l',string($t)) |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
80 else if ($t/@nr=7) |
39
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
81 then let $xref := substring-before($t,'!') return |
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
82 if ($xref=('[0]',$sheet-name)) |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
83 then (: it's a local reference after all :) |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
84 e:expand($tokens,$i+1,true(),$row,$col) |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
85 else let $ext := e:expand($tokens,$i+1,false(),$row,$col) return |
39
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
86 [$ext?1,e:external($xref,$ext?2)] |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
87 else if ($t/@nr=10) then e:amalgamate($tokens,$i+1,string($t)) |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
88 else if ($r[@nr=10 and .=':']) |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
89 then (: a range, takes priority :) |
39
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
90 [$i+3,e:range($tokens,$i,$local,$row,$col)] |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
91 else if ($t/@nr=8) then [$i+1,e:single(string($t),$row,$col)] |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
92 else if ($t/@nr=9) |
39
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
93 then if (matches($t,'^(true|false)$','i')) |
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
94 then e:exp1($i,upper-case($t),'b') |
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
95 else (: a variable name, I think :) if ($local) |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
96 then let $sub := e:tokenise(e:lookup(string($t)),$row,$col) return |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
97 [$i+1,$sub] |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
98 else (: can't expand :) e:exp1($i,'v',string($t)) |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
99 else (: shouldn't ever get here :) ()"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
100 </xsl:function> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
101 |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
102 <xsl:function name="e:amalgamate" as="array(*)"> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
103 <xsl:param name="tokens" as="element(xf:group)*"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
104 <xsl:param name="i" as="xs:integer"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
105 <xsl:param name="soFar" as="xs:string"/> |
39
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
106 <xsl:choose> |
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
107 <xsl:when test="$tokens[i]/@nr=10"> |
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
108 <xsl:sequence select="e:amalgamate($tokens,$i+1,concat($soFar, |
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
109 string($tokens[$i])))"/> |
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
110 </xsl:when> |
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
111 <xsl:otherwise> |
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
112 <xsl:variable name="res"> |
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
113 <x><xsl:value-of select="$soFar"/></x> |
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
114 </xsl:variable> |
40
ac6d1ca099f7
simplified rect output, refs (not refs2) working again
Henry S. Thompson <ht@markup.co.uk>
parents:
39
diff
changeset
|
115 <xsl:if test="false()"><xsl:message>amal: <xsl:value-of select="$res/."/></xsl:message></xsl:if> |
39
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
116 <xsl:sequence select="[$i,$res/*]"/> |
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
117 </xsl:otherwise> |
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
118 </xsl:choose> |
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
119 |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
120 </xsl:function> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
121 |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
122 <xsl:function name="e:exp1" as="array(*)"> |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
123 <xsl:param name="i" as="xs:integer"/> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
124 <xsl:param name="name" as="xs:string"/> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
125 <xsl:param name="val" as="xs:string"/> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
126 <xsl:variable name="elt"> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
127 <xsl:element name="{$name}" namespace="http://markup.co.uk/excel"> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
128 <xsl:value-of select="$val"/> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
129 </xsl:element> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
130 </xsl:variable> |
40
ac6d1ca099f7
simplified rect output, refs (not refs2) working again
Henry S. Thompson <ht@markup.co.uk>
parents:
39
diff
changeset
|
131 <xsl:if test="false()"><xsl:message>exp1: <xsl:value-of select="$name"/>|<xsl:value-of select="$val"/>|<xsl:value-of select="name($elt/*)"/></xsl:message></xsl:if> |
39
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
132 <xsl:sequence select="[$i+1,$elt/*]"/> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
133 </xsl:function> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
134 |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
135 <xsl:function name="e:single" as="element(e:s)"> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
136 <!-- I'm _guessing_ that external doesn't matter, i.e. that you |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
137 can copy an external relative ref and have it change --> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
138 <xsl:param name="val" as="xs:string"/> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
139 <xsl:param name="row" as="xs:integer"/> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
140 <xsl:param name="col" as="xs:integer"/> |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
141 <xsl:sequence select="e:cr($val,$row,$col)"/> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
142 </xsl:function> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
143 |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
144 <xsl:function name="e:range" as="element(e:r)"> |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
145 <xsl:param name="tokens" as="element(xf:group)*"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
146 <xsl:param name="i" as="xs:integer"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
147 <xsl:param name="local" as="xs:boolean"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
148 <xsl:param name="row" as="xs:integer"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
149 <xsl:param name="col" as="xs:integer"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
150 <xsl:variable name="l" select="$tokens[$i]"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
151 <xsl:variable name="r" select="$tokens[$i+2]"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
152 <xsl:variable name="lv" select="e:rPart($l,$local,$row,$col)"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
153 <xsl:variable name="rv" select="e:rPart($r,$local,$row,$col)"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
154 <r> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
155 <xsl:copy-of select="($lv,$rv)"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
156 </r> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
157 </xsl:function> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
158 |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
159 <xsl:function name="e:rPart" as="element(*)"> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
160 <xsl:param name="g" as="element(xf:group)"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
161 <xsl:param name="local" as="xs:boolean"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
162 <xsl:param name="row" as="xs:integer"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
163 <xsl:param name="col" as="xs:integer"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
164 <xsl:sequence select=" |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
165 if ($g/@nr=8) then e:single(string($g),$row,$col) |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
166 else if ($g/@nr=9) |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
167 then if ($local) |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
168 then let $tokens := e:tokenise(e:lookup(string($g)), |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
169 $row,$col) return |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
170 if (count($tokens)=1 and |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
171 $tokens[local-name()='s' or |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
172 (local-name()='e' and $tokens/e:s)]) |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
173 then $tokens |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
174 else e:badRP(string($g),$g/@nr,$local,$row,$col,$tokens) |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
175 else e:var(string($g)) |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
176 else e:badRP(string($g),$g/@nr,$local,$row,$col,())"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
177 </xsl:function> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
178 |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
179 <xsl:function name="e:var" as="element(e:v)"> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
180 <xsl:param name="name" as="xs:string"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
181 <v><xsl:value-of select="$name"/></v> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
182 </xsl:function> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
183 <xsl:function name="e:badRP" as="element(e:u)"> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
184 <xsl:param name="s" as="xs:string"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
185 <xsl:param name="t" as="xs:integer"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
186 <xsl:param name="local" as="xs:boolean"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
187 <xsl:param name="row" as="xs:integer"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
188 <xsl:param name="col" as="xs:integer"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
189 <xsl:param name="toks" as="element(*)*"/> |
39
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
190 <xsl:message>Bad range part in <xsl:value-of select="concat(e:n2a($col),$row)"/>: <xsl:value-of select="$s"/> of type <xsl:value-of select="$t"/> (<xsl:value-of select="if ($local) then 'local' else 'external'"/>: (<xsl:value-of select="string-join($toks,',')"/>)</xsl:message> |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
191 <u r="{concat(e:n2a($col),$row)}" s="{$s}" t="{$t}" local="{$local}"> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
192 <xsl:value-of select="string-join($toks,',')"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
193 </u> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
194 </xsl:function> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
195 |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
196 <xsl:function name="e:external" as="element(e:e)"> |
39
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
197 <xsl:param name="xref" as="xs:string" required="yes"/> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
198 <xsl:param name="ref" as="element(*)" required="yes"/> |
39
4c6a341e75da
big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents:
38
diff
changeset
|
199 <e x="{$xref}"><xsl:sequence select="$ref"/></e> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
200 </xsl:function> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
201 </xsl:stylesheet> |