Mercurial > hg > ooxml
annotate tokenise.xsl @ 38:468a6cf8bf0b
big change wrt formulae compiles, crashes
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Tue, 25 Apr 2017 22:17:12 +0100 |
parents | ac3cd8de7a10 |
children | 4c6a341e75da |
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> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
8 <xsl:param name="pat" select="$pat1"/><!-- xsl:param for refinement debugging by passing in the pattern --> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
9 |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
10 <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
|
11 <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
|
12 |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
13 <xsl:function name="e:lookup" as="xs:string*"> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
14 <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
|
15 <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
|
16 </xsl:function> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
17 |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
18 <xsl:function name="e:tokenise" as="element(*)*"> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
19 <!-- Tokenise a formula, recursively wrt variables |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
20 Output is composed of e:* as follows: |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
21 c: A list (function parameter) separator |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
22 e: An external (variable, cell or range) reference |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
23 f: A function name followed by an opening parenthesis |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
24 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
|
25 m: A constant matrix |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
26 p: A close-paren |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
27 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
|
28 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
|
29 s: A single-cell reference |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
30 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
|
31 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
|
32 --> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
33 <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
|
34 <!-- 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
|
35 <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
|
36 <xsl:param name="col" required="yes" as="xs:integer"/> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
37 <xsl:sequence select=" |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
38 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
|
39 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
|
40 </xsl:function> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
41 |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
42 <xsl:function name="e:tok1" as="element(*)*"> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
43 <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
|
44 <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
|
45 <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
|
46 <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
|
47 <xsl:param name="col" required="yes" as="xs:integer"/> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
48 <xsl:param name="soFar" required="yes" as="element(*)*"/> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
49 <xsl:sequence select=" |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
50 if ($i gt $n) |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
51 then $soFar |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
52 else |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
53 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
|
54 $j := $next?1, |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
55 $res := $next?2 return |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
56 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
|
57 </xsl:function> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
58 |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
59 <xsl:function name="e:expand" as="array(*)"> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
60 <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
|
61 <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
|
62 <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
|
63 <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
|
64 <xsl:param name="col" required="yes" as="xs:integer"/> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
65 <xsl:sequence select=" |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
66 let $t := $tokens[$i], |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
67 $r := $tokens[$i + 1] return |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
68 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
|
69 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
|
70 else if ($t/@nr=3) then e:exp1($i,'c',',') |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
71 else if ($t/@nr=4) then e:exp1($i,'f',string($t)) |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
72 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
|
73 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
|
74 else if ($t/@nr=7) |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
75 then if (substring-before($t,'!')=('[0]',$sheet-name)) |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
76 then (: it's a local reference after all :) |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
77 e:expand($tokens,$i+1,true(),$row,$col) |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
78 else let $ext := e:expand($tokens,$i+1,false(),$row,$col) return |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
79 [$ext?1,e:external($ext?2)] |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
80 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
|
81 else if ($r[@nr=10 and .=':']) |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
82 then (: a range, takes priority :) |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
83 [$i+2,e:range($tokens,$i,$local,$row,$col)] |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
84 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
|
85 else if ($t/@nr=9) |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
86 then if ($local) |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
87 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
|
88 [$i+1,$sub] |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
89 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
|
90 else (: shouldn't ever get here :) ()"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
91 </xsl:function> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
92 |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
93 <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
|
94 <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
|
95 <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
|
96 <xsl:param name="soFar" as="xs:string"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
97 <xsl:sequence select="if ($tokens[i]/@nr=10) |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
98 then e:amalgamate($tokens,$i+1,concat($soFar, |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
99 string($tokens[$i]))) |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
100 else [$i,$soFar]"/> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
101 </xsl:function> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
102 |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
103 <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
|
104 <xsl:param name="i" as="xs:integer"/> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
105 <xsl:param name="name" as="xs:string"/> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
106 <xsl:param name="val" as="xs:string"/> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
107 <xsl:variable name="elt"> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
108 <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
|
109 <xsl:value-of select="$val"/> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
110 </xsl:element> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
111 </xsl:variable> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
112 <xsl:sequence select="[$i+1,$elt]"/> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
113 </xsl:function> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
114 |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
115 <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
|
116 <!-- 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
|
117 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
|
118 <xsl:param name="val" as="xs:string"/> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
119 <xsl:param name="row" as="xs:integer"/> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
120 <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
|
121 <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
|
122 </xsl:function> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
123 |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
124 <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
|
125 <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
|
126 <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
|
127 <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
|
128 <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
|
129 <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
|
130 <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
|
131 <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
|
132 <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
|
133 <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
|
134 <r> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
135 <xsl:copy-of select="($lv,$rv)"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
136 </r> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
137 </xsl:function> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
138 |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
139 <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
|
140 <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
|
141 <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
|
142 <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
|
143 <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
|
144 <xsl:sequence select=" |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
145 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
|
146 else if ($g/@nr=9) |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
147 then if ($local) |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
148 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
|
149 $row,$col) return |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
150 if (count($tokens)=1 and |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
151 $tokens[local-name()='s' or |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
152 (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
|
153 then $tokens |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
154 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
|
155 else e:var(string($g)) |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
156 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
|
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:var" as="element(e:v)"> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
160 <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
|
161 <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
|
162 </xsl:function> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
163 <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
|
164 <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
|
165 <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
|
166 <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
|
167 <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
|
168 <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
|
169 <xsl:param name="toks" as="element(*)*"/> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
170 <xsl:message terminate="yes">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> |
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
171 <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
|
172 <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
|
173 </u> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
174 </xsl:function> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
175 |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
176 <xsl:function name="e:external" as="element(e:e)"> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
177 <xsl:param name="ref" as="element(*)" required="yes"/> |
38
468a6cf8bf0b
big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents:
37
diff
changeset
|
178 <e><xsl:sequence select="$ref"/></e> |
37
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
179 </xsl:function> |
ac3cd8de7a10
towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff
changeset
|
180 </xsl:stylesheet> |