Mercurial > hg > ooxml
changeset 40:ac6d1ca099f7
simplified rect output, refs (not refs2) working again
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Tue, 02 May 2017 09:20:13 +0100 |
parents | 4c6a341e75da |
children | afda541de4c4 |
files | rect.xsl refs.xsl refs2.xsl tokenise.xsl visualise.xpl |
diffstat | 5 files changed, 60 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/rect.xsl Wed Apr 26 18:51:34 2017 +0100 +++ b/rect.xsl Tue May 02 09:20:13 2017 +0100 @@ -1,16 +1,12 @@ <?xml version='1.0'?> <!DOCTYPE doc SYSTEM "../../../lib/xml/xsl.dtd" > -<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 xpf" xmlns="http://markup.co.uk/excel" xmlns:xpf="http://www.w3.org/2005/xpath-functions"> +<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 xpf e" xmlns="http://markup.co.uk/excel" xmlns:xpf="http://www.w3.org/2005/xpath-functions"> <xsl:strip-space elements="s:sheetData"/> <xsl:include href="a2n.xsl"/> <xsl:include href="n2a.xsl"/> <xsl:include href="tokenise.xsl"/> - <xsl:variable name="refs" select="document('sample2/empty_refs.xml')/*"/><!--collection()[2]/*--> - - <xsl:key name="ref" match="e:i" use="@r"/> - <xsl:variable name="dim" select="//s:dimension/@ref"/> <xsl:template match="/"> @@ -34,21 +30,17 @@ <xsl:variable name="col" select="."/> <xsl:variable name="r" select="concat(e:n2a($col),string($row))"/> <xsl:variable name="c" select="$cells[@r=$r]"/> - <xsl:variable name="reffed" select="key('ref',$r,$refs)"/> <c c="{$col}"> <xsl:if test="$c/s:f"><xsl:attribute name="f">1</xsl:attribute></xsl:if> <xsl:if test="$c/*"> - <t> - <xsl:if test="$c/@e:class"><xsl:attribute name="c"><xsl:value-of select="substring($c/@e:class,1,1)"/></xsl:attribute></xsl:if> + <xsl:if test="$c/@e:class"><xsl:attribute name="t"><xsl:value-of select="substring($c/@e:class,1,1)"/></xsl:attribute></xsl:if> <xsl:if test="$c/@e:code"><xsl:attribute name="l"><xsl:value-of select="$c/@e:code"/></xsl:attribute></xsl:if> <xsl:if test="$c/s:f"> <f> <xsl:copy-of select="e:tokenise($c/s:f,$row,$col)"/> </f></xsl:if> - <xsl:value-of select="substring($c/@e:type,1,1)"/> - </t> + <xsl:value-of select="substring($c/@e:type,1,1)"/> </xsl:if> - <xsl:if test="$reffed"><xsl:copy-of select="$reffed/e:r"/></xsl:if> </c> </xsl:for-each></xsl:if> </r>
--- a/refs.xsl Wed Apr 26 18:51:34 2017 +0100 +++ b/refs.xsl Tue May 02 09:20:13 2017 +0100 @@ -2,19 +2,23 @@ <!DOCTYPE xsl:stylesheet SYSTEM "../../../lib/xml/xsl.dtd" > <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:include href="a2n.xsl"/> - - <xsl:param name="sheet-name"/> + <xsl:include href="n2a.xsl"/> <xsl:template match="/"> - <refs sheetName="{$sheet-name}"><xsl:apply-templates select="//s:c"/></refs> + <refs><xsl:apply-templates select="//e:c"/></refs> </xsl:template> - <xsl:template match="e:c[e:f]"> - <xsl:variable name="cr" select="e:cr(@r,0,0)"/> - <xsl:if test="@r='xxx'"><xsl:message><xsl:value-of select="count(e:f/*)"/>|</xsl:message> + <xsl:template match="e:c[e:f/(e:s|e:r)]"> + <xsl:variable name="r" select="../@r"/> + <xsl:variable name="c" select="@c"/> + <xsl:if test="@r='xxx' and @c='1'"><xsl:message><xsl:value-of select="count(e:f/*)"/>|</xsl:message> </xsl:if> + <ref r="{e:n2a($c)}{$r}"><xsl:apply-templates select="e:f/(e:s|e:r)"/></ref> </xsl:template> - <xsl:template match="s:c"/> + <xsl:template match="e:c"/> + + <xsl:template match="node()|@*"> + <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy> + </xsl:template> </xsl:stylesheet>
--- a/refs2.xsl Wed Apr 26 18:51:34 2017 +0100 +++ b/refs2.xsl Tue May 02 09:20:13 2017 +0100 @@ -2,9 +2,9 @@ <!DOCTYPE doc SYSTEM "../../../lib/xml/xsl.dtd" > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:e="http://markup.co.uk/excel" exclude-result-prefixes="xs e" xmlns="http://markup.co.uk/excel"> <!-- Invert the singleton references extracted from formulae by refs.xsl - Input e:refs/e:ref/e:s e:ref[@c] contains one or more e:s - for each singleton reference - to e:s/@r in c's formula + Input e:refs/e:ref/e:s e:ref[@r] contains one or more e:s or e:r + for each singleton/range reference + to e:s/@r in @r's formula Output e:refs/e:i/e:r e:i[@r] contains one e:r for each cell which references r -->
--- a/tokenise.xsl Wed Apr 26 18:51:34 2017 +0100 +++ b/tokenise.xsl Tue May 02 09:20:13 2017 +0100 @@ -22,9 +22,9 @@ b: Boolean constant c: A list (function parameter) separator e: An external (variable, cell or range) reference - f: A function name followed by an opening parenthesis l: The beginning of the formula or an opening paren m: A constant matrix + o: A function name followed by an opening parenthesis p: A close-paren q: A text (delimited by double quotes) r: A range reference (two children, either e or s or u (unsupported)) @@ -36,7 +36,7 @@ <!-- The row and column number of the cell whence the formula came --> <xsl:param name="row" required="yes" as="xs:integer"/> <xsl:param name="col" required="yes" as="xs:integer"/> - <xsl:message>tok: <xsl:value-of select="$formula"/></xsl:message> + <xsl:if test="false()"><xsl:message>tok: <xsl:value-of select="$formula"/></xsl:message></xsl:if> <xsl:sequence select=" let $tokens := analyze-string($formula,$pat)/xf:match/xf:group return e:tok1($tokens,count($tokens),1,$row,$col,())"/> @@ -50,7 +50,7 @@ <xsl:param name="col" required="yes" as="xs:integer"/> <xsl:param name="soFar" as="element(*)*"/> <xsl:variable name="last" select="$soFar[count($soFar)]"></xsl:variable> - <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 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> <xsl:sequence select=" if ($i gt $n) then $soFar @@ -67,14 +67,14 @@ <xsl:param name="local" required="yes" as="xs:boolean"/> <xsl:param name="row" required="yes" as="xs:integer"/> <xsl:param name="col" required="yes" as="xs:integer"/> - <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 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> <xsl:sequence select=" let $t := $tokens[$i], $r := $tokens[$i + 1] return if ($t/@nr=1) then e:exp1($i,'q',string($t)) else if ($t/@nr=2) then e:exp1($i,'m',string($t)) else if ($t/@nr=3) then e:exp1($i,'c',',') - else if ($t/@nr=4) then e:exp1($i,'f',string($t)) + else if ($t/@nr=4) then e:exp1($i,'o',string($t)) else if ($t/@nr=5) then e:exp1($i,'p',')') else if ($t/@nr=6) then e:exp1($i,'l',string($t)) else if ($t/@nr=7) @@ -112,7 +112,7 @@ <xsl:variable name="res"> <x><xsl:value-of select="$soFar"/></x> </xsl:variable> - <xsl:message>amal: <xsl:value-of select="$res/."/></xsl:message> + <xsl:if test="false()"><xsl:message>amal: <xsl:value-of select="$res/."/></xsl:message></xsl:if> <xsl:sequence select="[$i,$res/*]"/> </xsl:otherwise> </xsl:choose> @@ -128,7 +128,7 @@ <xsl:value-of select="$val"/> </xsl:element> </xsl:variable> - <xsl:message>exp1: <xsl:value-of select="$name"/>|<xsl:value-of select="$val"/>|<xsl:value-of select="name($elt/*)"/></xsl:message> + <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> <xsl:sequence select="[$i+1,$elt/*]"/> </xsl:function>
--- a/visualise.xpl Wed Apr 26 18:51:34 2017 +0100 +++ b/visualise.xpl Tue May 02 09:20:13 2017 +0100 @@ -70,6 +70,21 @@ <p:with-param name="xlDir" select="$root"/> </p:xslt> + <p:load name="ss2"> + <p:with-option name="href" select="concat($elabDir,'/rect.xsl')"/> + </p:load> + + <p:xslt name="rect"> + <p:input port="source"> + <p:pipe step="format" port="result"/> + </p:input> + <p:input port="stylesheet"> + <p:pipe step="ss2" port="result"/> + </p:input> + <p:with-param name="sheet-number" select="$sheet-number"/> + <p:with-param name="xlDir" select="$root"/> + </p:xslt> + <p:load name="ssr"> <p:with-option name="href" select="concat($elabDir,'/refs.xsl')"/> <p:documentation> @@ -79,7 +94,7 @@ <p:xslt name="refs"> <p:input port="source"> - <p:pipe step="vis" port="source"/> + <p:pipe step="rect" port="result"/> </p:input> <p:input port="stylesheet"> <p:pipe step="ssr" port="result"/> @@ -103,21 +118,22 @@ <p:pipe step="ssr2" port="result"/> </p:input> </p:xslt> - - <p:load name="ss2"> - <p:with-option name="href" select="concat($elabDir,'/rect.xsl')"/> + + <p:load name="ssg"> + <p:with-option name="href" select="concat($elabDir,'/merge.xsl')"/> + <p:documentation> + <div>Combine rectangular array and inverted ref table</div> + </p:documentation> </p:load> - <p:xslt name="rect"> - <p:input port="source"> - <p:pipe step="format" port="result"/> - <p:pipe step="refs2" port="result"/> - </p:input> + <p:xslt name="merge"> + <p:input port="source"> + <p:pipe step="rect" port="result"/> + <p:pipe step="refs2" port="result"/> + </p:input> <p:input port="stylesheet"> - <p:pipe step="ss2" port="result"/> - </p:input> - <p:with-param name="sheet-number" select="$sheet-number"/> - <p:with-param name="xlDir" select="$root"/> + <p:pipe step="ssg" port="result"/> + </p:input> </p:xslt> <p:choose> @@ -127,7 +143,7 @@ </p:load> <p:xslt name="fmt"> <p:input port="source"> - <p:pipe step="rect" port="result"/> + <p:pipe step="merge" port="result"/> </p:input> <p:input port="stylesheet"> <p:pipe step="ss3" port="result"/> @@ -135,7 +151,11 @@ </p:xslt> </p:when> <p:otherwise> - <p:identity/> + <p:identity> + <p:input port="source"> + <p:pipe step="merge" port="result"/> + </p:input> + </p:identity> </p:otherwise> </p:choose> </p:pipeline>