annotate tokenise.xsl @ 52:9bb415e0adc9

try to fix error processin odd REUTER|IDN\!'.SPX' external ref
author Henry S. Thompson <ht@markup.co.uk>
date Tue, 16 May 2017 17:28:52 +0100
parents ac6d1ca099f7
children 8000dbed09df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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" >
52
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
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"> <xsl:param name="sheet-number"/>
37
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
4 <xsl:param name="xlDir"/>
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
5
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
6 <xsl:variable name="pat1">("[^"]*")|(\{[^}]+})|(,)|([^=\-+*/();:,.$&lt;>^!]+(?:\.[^=\-+*/();:,.$&lt;>^!]+)*\()|([)])|(^=|\()|((?:(?:'[^']+')|(?:\[[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
7 <xsl:variable name="pat2">("[^"]*")|(\{[^}]+})|(,)|([^=\-+*/();:,.$&lt;>^!]+(?:\.[^=\-+*/();:,.$&lt;>^!]+)*\()|([)])|(^=|\()|((?:'[^']+'!)|(?:[\[0-9A-Za-z_][^=\-+*/();:,.$&lt;>^!]*!))|(\$?[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
8 <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
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:
39
4c6a341e75da big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents: 38
diff changeset
21 b: Boolean constant
37
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
22 c: A list (function parameter) separator
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
23 e: An external (variable, cell or range) reference
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
40
ac6d1ca099f7 simplified rect output, refs (not refs2) working again
Henry S. Thompson <ht@markup.co.uk>
parents: 39
diff changeset
26 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
27 p: A close-paren
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
28 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
29 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
30 s: A single-cell reference
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
31 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
32 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
33 -->
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
34 <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
35 <!-- 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
36 <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
37 <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
38 <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
39 <xsl:sequence select="
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
40 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
41 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
42 </xsl:function>
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
43
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
44 <xsl:function name="e:tok1" as="element(*)*">
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
45 <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
46 <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
47 <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
48 <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
49 <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
50 <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
51 <xsl:variable name="last" select="$soFar[count($soFar)]"></xsl:variable>
52
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
52 <xsl:if test="$row=5 and $col=1"><xsl:message>tok1: <xsl:value-of select="$n"/>|<xsl:value-of select="$i"/>|<xsl:value-of select="if ($i=1) then string-join($tokens,'\') else $tokens[$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>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
53 <!-- Tail-recursion incrementing index $i into $tokens -->
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"/>
52
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
70 <!-- Consume one or more tokens, returns new index and an element -->
40
ac6d1ca099f7 simplified rect output, refs (not refs2) working again
Henry S. Thompson <ht@markup.co.uk>
parents: 39
diff changeset
71 <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
72 <xsl:sequence select="
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
73 let $t := $tokens[$i],
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
74 $r := $tokens[$i + 1] return
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
75 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
76 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
77 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
78 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
79 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
80 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
81 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
82 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
83 if ($xref=('[0]',$sheet-name))
37
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
84 then (: it's a local reference after all :)
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
85 e:expand($tokens,$i+1,true(),$row,$col)
52
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
86 else let $ext := if ($tokens[$i+1]=&quot;'&quot;)
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
87 then (: odd case, see notes wrt enron/kenneth_lay :)
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
88 e:oddx($tokens,$i+2,$tokens[$i+1])
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
89 else
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
90 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
91 [$ext?1,e:external($xref,$ext?2)]
52
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
92 else if ($t/@nr=10) then e:misc($tokens,$i+1,string($t))
37
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
93 else if ($r[@nr=10 and .=':'])
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
94 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
95 [$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
96 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
97 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
98 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
99 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
100 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
101 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
102 [$i+1,$sub]
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
103 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
104 else (: shouldn't ever get here :) ()"/>
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
105 </xsl:function>
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
106
52
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
107 <xsl:function name="e:misc">
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
108 <xsl:param name="tokens" as="element(xf:group)*"/>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
109 <xsl:param name="i" as="xs:integer"/>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
110 <xsl:param name="soFar" as="xs:string"/>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
111 <!-- Amalgamate bits of type 10 and wrap in <x> -->
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
112 <xsl:variable name="content" select="e:amalgamate($tokens,$i,$soFar,10,'')"/>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
113 <xsl:variable name="x"><x><xsl:value-of select="$content?2"/></x></xsl:variable>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
114 <xsl:sequence select="[$content?1,$x/*]"/>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
115 </xsl:function>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
116
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
117 <xsl:function name="e:oddx">
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
118 <xsl:param name="tokens" as="element(xf:group)*"/>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
119 <xsl:param name="i" as="xs:integer"/>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
120 <xsl:param name="soFar" as="xs:string"/><!-- Will always be a lonely ' -->
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
121 <!-- Amalgamate bits of type 9 and 10 as <v> for wrapping in <e> -->
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
122 <xsl:variable name="content" select="e:amalgamate($tokens,$i,$soFar,10,$soFar)"/>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
123 <xsl:variable name="x"><v><xsl:value-of select="
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
124 if ($tokens[$content?1]=$soFar)
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
125 then $content?2
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
126 else e:shouldnt('oddx',$tokens[$content?1])"/></v></xsl:variable>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
127 <xsl:sequence select="[$content?1+1,$x/*]"/>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
128 </xsl:function>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
129
38
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
130 <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
131 <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
132 <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
133 <xsl:param name="soFar" as="xs:string"/>
52
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
134 <xsl:param name="nrs" as="xs:integer*"/>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
135 <xsl:param name="stop" 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
136 <xsl:choose>
52
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
137 <xsl:when test="$tokens[$i]/@nr=$nrs and $tokens[$i]!=$stop">
39
4c6a341e75da big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents: 38
diff changeset
138 <xsl:sequence select="e:amalgamate($tokens,$i+1,concat($soFar,
52
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
139 string($tokens[$i])),
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
140 $nrs,$stop)"/>
39
4c6a341e75da big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents: 38
diff changeset
141 </xsl:when>
4c6a341e75da big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents: 38
diff changeset
142 <xsl:otherwise>
52
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
143 <xsl:if test="false()"><xsl:message>amal <xsl:value-of select="$nrs"/>: <xsl:value-of select="$soFar"/></xsl:message></xsl:if>
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
144 <xsl:sequence select="[$i,$soFar]"/>
39
4c6a341e75da big rework works on sample2, w/o refs processing
Henry S. Thompson <ht@markup.co.uk>
parents: 38
diff changeset
145 </xsl:otherwise>
52
9bb415e0adc9 try to fix error processin odd REUTER|IDN\!'.SPX' external ref
Henry S. Thompson <ht@markup.co.uk>
parents: 40
diff changeset
146 </xsl:choose>
37
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
147 </xsl:function>
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
148
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
149 <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
150 <xsl:param name="i" as="xs:integer"/>
37
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
151 <xsl:param name="name" as="xs:string"/>
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
152 <xsl:param name="val" as="xs:string"/>
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
153 <xsl:variable name="elt">
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
154 <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
155 <xsl:value-of select="$val"/>
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
156 </xsl:element>
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
157 </xsl:variable>
40
ac6d1ca099f7 simplified rect output, refs (not refs2) working again
Henry S. Thompson <ht@markup.co.uk>
parents: 39
diff changeset
158 <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
159 <xsl:sequence select="[$i+1,$elt/*]"/>
37
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
160 </xsl:function>
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
161
38
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
162 <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
163 <!-- 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
164 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
165 <xsl:param name="val" as="xs:string"/>
37
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
166 <xsl:param name="row" as="xs:integer"/>
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
167 <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
168 <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
169 </xsl:function>
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
170
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
171 <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
172 <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
173 <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
174 <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
175 <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
176 <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
177 <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
178 <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
179 <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
180 <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
181 <r>
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
182 <xsl:copy-of select="($lv,$rv)"/>
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
183 </r>
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
184 </xsl:function>
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
185
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
186 <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
187 <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
188 <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
189 <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
190 <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
191 <xsl:sequence select="
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
192 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
193 else if ($g/@nr=9)
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
194 then if ($local)
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
195 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
196 $row,$col) return
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
197 if (count($tokens)=1 and
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
198 $tokens[local-name()='s' or
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
199 (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
200 then $tokens
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
201 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
202 else e:var(string($g))
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
203 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
204 </xsl:function>
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
205
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
206 <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
207 <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
208 <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
209 </xsl:function>
468a6cf8bf0b big change wrt formulae compiles, crashes
Henry S. Thompson <ht@markup.co.uk>
parents: 37
diff changeset
210 <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
211 <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
212 <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
213 <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
214 <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
215 <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
216 <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
217 <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
218 <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
219 <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
220 </u>
37
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
221 </xsl:function>
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
222
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
223 <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
224 <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
225 <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
226 <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
227 </xsl:function>
ac3cd8de7a10 towards big rework of tokenisation
Henry S. Thompson <ht@markup.co.uk>
parents:
diff changeset
228 </xsl:stylesheet>