Mercurial > hg > ooxml
comparison 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 |
comparison
equal
deleted
inserted
replaced
51:793496d2d165 | 52:9bb415e0adc9 |
---|---|
1 <?xml version='1.0'?> | 1 <?xml version='1.0'?> |
2 <!DOCTYPE xsl:stylesheet SYSTEM "../../../lib/xml/xsl.dtd" > | 2 <!DOCTYPE xsl:stylesheet SYSTEM "../../../lib/xml/xsl.dtd" > |
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"> | 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"/> |
4 <xsl:param name="sheet-number"/> | |
5 <xsl:param name="xlDir"/> | 4 <xsl:param name="xlDir"/> |
6 | 5 |
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> | 6 <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> |
8 <xsl:variable name="pat2">("[^"]*")|(\{[^}]+})|(,)|([^=\-+*/();:,.$<>^!]+(?:\.[^=\-+*/();:,.$<>^!]+)*\()|([)])|(^=|\()|((?:'[^']+'!)|(?:[\[0-9A-Za-z_][^=\-+*/();:,.$<>^!]*!))|(\$?[A-Z]+\$?[0-9]+)|([a-zA-Z_\\][a-zA-Z0-9._]*)|(.)</xsl:variable> | 7 <xsl:variable name="pat2">("[^"]*")|(\{[^}]+})|(,)|([^=\-+*/();:,.$<>^!]+(?:\.[^=\-+*/();:,.$<>^!]+)*\()|([)])|(^=|\()|((?:'[^']+'!)|(?:[\[0-9A-Za-z_][^=\-+*/();:,.$<>^!]*!))|(\$?[A-Z]+\$?[0-9]+)|([a-zA-Z_\\][a-zA-Z0-9._]*)|(.)</xsl:variable> |
9 <xsl:param name="pat" select="$pat2"/><!-- xsl:param for refinement debugging by passing in the pattern --> | 8 <xsl:param name="pat" select="$pat2"/><!-- xsl:param for refinement debugging by passing in the pattern --> |
48 <xsl:param name="i" required="yes" as="xs:integer"/> | 47 <xsl:param name="i" required="yes" as="xs:integer"/> |
49 <xsl:param name="row" required="yes" as="xs:integer"/> | 48 <xsl:param name="row" required="yes" as="xs:integer"/> |
50 <xsl:param name="col" required="yes" as="xs:integer"/> | 49 <xsl:param name="col" required="yes" as="xs:integer"/> |
51 <xsl:param name="soFar" as="element(*)*"/> | 50 <xsl:param name="soFar" as="element(*)*"/> |
52 <xsl:variable name="last" select="$soFar[count($soFar)]"></xsl:variable> | 51 <xsl:variable name="last" select="$soFar[count($soFar)]"></xsl:variable> |
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> | 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> |
53 <!-- Tail-recursion incrementing index $i into $tokens --> | |
54 <xsl:sequence select=" | 54 <xsl:sequence select=" |
55 if ($i gt $n) | 55 if ($i gt $n) |
56 then $soFar | 56 then $soFar |
57 else | 57 else |
58 let $next := e:expand($tokens,$i,true(),$row,$col), | 58 let $next := e:expand($tokens,$i,true(),$row,$col), |
65 <xsl:param name="tokens" required="yes" as="element(xf:group)*"/> | 65 <xsl:param name="tokens" required="yes" as="element(xf:group)*"/> |
66 <xsl:param name="i" required="yes" as="xs:integer"/> | 66 <xsl:param name="i" required="yes" as="xs:integer"/> |
67 <xsl:param name="local" required="yes" as="xs:boolean"/> | 67 <xsl:param name="local" required="yes" as="xs:boolean"/> |
68 <xsl:param name="row" required="yes" as="xs:integer"/> | 68 <xsl:param name="row" required="yes" as="xs:integer"/> |
69 <xsl:param name="col" required="yes" as="xs:integer"/> | 69 <xsl:param name="col" required="yes" as="xs:integer"/> |
70 <!-- Consume one or more tokens, returns new index and an element --> | |
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> | 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> |
71 <xsl:sequence select=" | 72 <xsl:sequence select=" |
72 let $t := $tokens[$i], | 73 let $t := $tokens[$i], |
73 $r := $tokens[$i + 1] return | 74 $r := $tokens[$i + 1] return |
74 if ($t/@nr=1) then e:exp1($i,'q',string($t)) | 75 if ($t/@nr=1) then e:exp1($i,'q',string($t)) |
80 else if ($t/@nr=7) | 81 else if ($t/@nr=7) |
81 then let $xref := substring-before($t,'!') return | 82 then let $xref := substring-before($t,'!') return |
82 if ($xref=('[0]',$sheet-name)) | 83 if ($xref=('[0]',$sheet-name)) |
83 then (: it's a local reference after all :) | 84 then (: it's a local reference after all :) |
84 e:expand($tokens,$i+1,true(),$row,$col) | 85 e:expand($tokens,$i+1,true(),$row,$col) |
85 else let $ext := e:expand($tokens,$i+1,false(),$row,$col) return | 86 else let $ext := if ($tokens[$i+1]="'") |
87 then (: odd case, see notes wrt enron/kenneth_lay :) | |
88 e:oddx($tokens,$i+2,$tokens[$i+1]) | |
89 else | |
90 e:expand($tokens,$i+1,false(),$row,$col) return | |
86 [$ext?1,e:external($xref,$ext?2)] | 91 [$ext?1,e:external($xref,$ext?2)] |
87 else if ($t/@nr=10) then e:amalgamate($tokens,$i+1,string($t)) | 92 else if ($t/@nr=10) then e:misc($tokens,$i+1,string($t)) |
88 else if ($r[@nr=10 and .=':']) | 93 else if ($r[@nr=10 and .=':']) |
89 then (: a range, takes priority :) | 94 then (: a range, takes priority :) |
90 [$i+3,e:range($tokens,$i,$local,$row,$col)] | 95 [$i+3,e:range($tokens,$i,$local,$row,$col)] |
91 else if ($t/@nr=8) then [$i+1,e:single(string($t),$row,$col)] | 96 else if ($t/@nr=8) then [$i+1,e:single(string($t),$row,$col)] |
92 else if ($t/@nr=9) | 97 else if ($t/@nr=9) |
97 [$i+1,$sub] | 102 [$i+1,$sub] |
98 else (: can't expand :) e:exp1($i,'v',string($t)) | 103 else (: can't expand :) e:exp1($i,'v',string($t)) |
99 else (: shouldn't ever get here :) ()"/> | 104 else (: shouldn't ever get here :) ()"/> |
100 </xsl:function> | 105 </xsl:function> |
101 | 106 |
107 <xsl:function name="e:misc"> | |
108 <xsl:param name="tokens" as="element(xf:group)*"/> | |
109 <xsl:param name="i" as="xs:integer"/> | |
110 <xsl:param name="soFar" as="xs:string"/> | |
111 <!-- Amalgamate bits of type 10 and wrap in <x> --> | |
112 <xsl:variable name="content" select="e:amalgamate($tokens,$i,$soFar,10,'')"/> | |
113 <xsl:variable name="x"><x><xsl:value-of select="$content?2"/></x></xsl:variable> | |
114 <xsl:sequence select="[$content?1,$x/*]"/> | |
115 </xsl:function> | |
116 | |
117 <xsl:function name="e:oddx"> | |
118 <xsl:param name="tokens" as="element(xf:group)*"/> | |
119 <xsl:param name="i" as="xs:integer"/> | |
120 <xsl:param name="soFar" as="xs:string"/><!-- Will always be a lonely ' --> | |
121 <!-- Amalgamate bits of type 9 and 10 as <v> for wrapping in <e> --> | |
122 <xsl:variable name="content" select="e:amalgamate($tokens,$i,$soFar,10,$soFar)"/> | |
123 <xsl:variable name="x"><v><xsl:value-of select=" | |
124 if ($tokens[$content?1]=$soFar) | |
125 then $content?2 | |
126 else e:shouldnt('oddx',$tokens[$content?1])"/></v></xsl:variable> | |
127 <xsl:sequence select="[$content?1+1,$x/*]"/> | |
128 </xsl:function> | |
129 | |
102 <xsl:function name="e:amalgamate" as="array(*)"> | 130 <xsl:function name="e:amalgamate" as="array(*)"> |
103 <xsl:param name="tokens" as="element(xf:group)*"/> | 131 <xsl:param name="tokens" as="element(xf:group)*"/> |
104 <xsl:param name="i" as="xs:integer"/> | 132 <xsl:param name="i" as="xs:integer"/> |
105 <xsl:param name="soFar" as="xs:string"/> | 133 <xsl:param name="soFar" as="xs:string"/> |
134 <xsl:param name="nrs" as="xs:integer*"/> | |
135 <xsl:param name="stop" as="xs:string"/> | |
106 <xsl:choose> | 136 <xsl:choose> |
107 <xsl:when test="$tokens[i]/@nr=10"> | 137 <xsl:when test="$tokens[$i]/@nr=$nrs and $tokens[$i]!=$stop"> |
108 <xsl:sequence select="e:amalgamate($tokens,$i+1,concat($soFar, | 138 <xsl:sequence select="e:amalgamate($tokens,$i+1,concat($soFar, |
109 string($tokens[$i])))"/> | 139 string($tokens[$i])), |
140 $nrs,$stop)"/> | |
110 </xsl:when> | 141 </xsl:when> |
111 <xsl:otherwise> | 142 <xsl:otherwise> |
112 <xsl:variable name="res"> | 143 <xsl:if test="false()"><xsl:message>amal <xsl:value-of select="$nrs"/>: <xsl:value-of select="$soFar"/></xsl:message></xsl:if> |
113 <x><xsl:value-of select="$soFar"/></x> | 144 <xsl:sequence select="[$i,$soFar]"/> |
114 </xsl:variable> | |
115 <xsl:if test="false()"><xsl:message>amal: <xsl:value-of select="$res/."/></xsl:message></xsl:if> | |
116 <xsl:sequence select="[$i,$res/*]"/> | |
117 </xsl:otherwise> | 145 </xsl:otherwise> |
118 </xsl:choose> | 146 </xsl:choose> |
119 | |
120 </xsl:function> | 147 </xsl:function> |
121 | 148 |
122 <xsl:function name="e:exp1" as="array(*)"> | 149 <xsl:function name="e:exp1" as="array(*)"> |
123 <xsl:param name="i" as="xs:integer"/> | 150 <xsl:param name="i" as="xs:integer"/> |
124 <xsl:param name="name" as="xs:string"/> | 151 <xsl:param name="name" as="xs:string"/> |