Mercurial > hg > ooxml
diff refs.xsl @ 36:ae605b77d1e4
compute (but not use) master formula cells info,
extend refs collection to include abs/reloc info
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Tue, 25 Apr 2017 12:24:31 +0100 |
parents | 93fd0d532754 |
children | ac3cd8de7a10 |
line wrap: on
line diff
--- a/refs.xsl Thu Apr 13 23:09:58 2017 +0100 +++ b/refs.xsl Tue Apr 25 12:24:31 2017 +0100 @@ -3,6 +3,8 @@ <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"/> <xsl:param name="xlDir"/> + + <xsl:include href="a2n.xsl"/> <xsl:variable name="pat1">("[^"]*")|(\{[^}]+})|(,)|([^=\-+*/();:,.$<>^!]+(?:\.[^=\-+*/();:,.$<>^!]+)*\()|([)])|(^=|\()|((?:'[^']+')|(?:\[[0-9]+\][^!]*))|(\$?[A-Z]+\$?[0-9]+)|([a-zA-Z_\\][a-zA-Z0-9._]*)|(.)</xsl:variable> <xsl:param name="pat" select="$pat1"/><!-- xsl:param for refinement debugging by passing in the pattern --> @@ -23,6 +25,9 @@ <xsl:function name="e:tokenise" as="array(element(*)*)*"> <!-- Tokenise a formula, recursively wrt variables --> <xsl:param name="formula" as="xs:string" required="yes"/> + <!-- The row and column number of the cell whence the formula came --> + <xsl:param name="row" required="yes" as="xs:int"/> + <xsl:param name="col" required="yes" as="xs:int"/> <xsl:sequence select=" let $tokens := analyze-string($formula,$pat)/xf:match/xf:group return if ($tokens[@nr=(7,8,9)]) @@ -40,7 +45,8 @@ else (), $defns := for $var in $vars return e:lookup($var), $recur := for $sub in $defns - return if ($sub) then e:tokenise($sub) else (), + return if ($sub) then e:tokenise($sub,$row,$col) + else (), $singles := for $i in (1 to $n) return let $t := $tokens[$i], $l := $tokens[$i - 1], @@ -49,7 +55,7 @@ not($l[@nr=10 and .=(':','!')]) and not($r[@nr=10 and .=':'])) - then e:single($t,false()) + then e:single($t,$row,$col,false()) else (), $ranges := for $i in (1 to count($tokens)) return let $t := $tokens[$i] return @@ -58,8 +64,10 @@ $tokens[$i - 2][@nr=10 and .='!'])]) then let $l := $tokens[$i - 1], $r := $tokens[$i + 1] - return e:range(e:single($l,false()), - e:single($r,false())) + return e:range(e:single($l, + $row,$col,false()), + e:single($r, + $row,$col,false())) else (), $externals := for $i in (1 to count($tokens)) return let $t := $tokens[$i] return @@ -67,12 +75,12 @@ then let $ext := $t!='[0]', $ref := e:single($tokens[$i + 2], - $ext), + $row,$col,$ext), $res := if ((($i+3) le $n) and $tokens[$i + 3][@nr=10 and .=':']) then e:range($ref, e:single($tokens[$i+4], - $ext)) + $row,$col,$ext)) else $ref return if ($ext) then e:external($t,$res) @@ -86,18 +94,19 @@ <xsl:function name="e:single" as="element(*)"> <xsl:param name="group" as="element(xf:group)"/> + <xsl:param name="row" as="xs:integer"/> + <xsl:param name="col" as="xs:integer"/> <xsl:param name="external" as="xs:boolean"/> <xsl:variable name="val" select="if ($group/@nr=9) then e:lookup($group) else string($group)"/> <xsl:choose> <xsl:when test="count($val)>0 or not($external)"> - <s><xsl:value-of select="$val"/></s> + <xsl:sequence select="e:cr($val,$row,$col)"/> </xsl:when> <xsl:otherwise> <v><xsl:value-of select="$group"/></v> </xsl:otherwise> - </xsl:choose> - + </xsl:choose> </xsl:function> <xsl:function name="e:range" as="element(e:r)"> @@ -117,7 +126,8 @@ </xsl:template> <xsl:template match="s:c[s:f]"> - <xsl:variable name="tokens" select="e:tokenise(s:f/.)"/> + <xsl:variable name="cr" select="e:cr(@r,0,0)"/> + <xsl:variable name="tokens" select="e:tokenise(s:f/.,$cr/e:r[1],$cr/e:r[2])"/> <xsl:if test="@r='xxx'"><xsl:message><xsl:value-of select="s:f"/>|<xsl:value-of select="(analyze-string(s:f/.,$pat)/xf:match/xf:group)[3]/@nr"/></xsl:message> </xsl:if> <xsl:if test="count($tokens)>0">