Mercurial > hg > ooxml
changeset 48:5d9806f90896
basic integration of shared, but copying <f> is wrong, should reconstruct by denormalising <nf> for new home
author | Henry S. Thompson <ht@markup.co.uk> |
---|---|
date | Wed, 10 May 2017 16:52:04 +0100 |
parents | 3e9a3e51627e |
children | d3569a8cbf7a |
files | a2n.xsl merge.xsl notes.txt rect.xsl shared.xsl visualise.xpl |
diffstat | 6 files changed, 105 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/a2n.xsl Tue May 09 23:08:18 2017 +0100 +++ b/a2n.xsl Wed May 10 16:52:04 2017 +0100 @@ -13,13 +13,18 @@ else $lv+(26*e:a2n(substring($aa,1,$l - 1)))"/> </xsl:function> + <xsl:function name="e:pr" as="element(xpf:analyze-string-result)"> + <xsl:param name="ref" as="xs:string"/> + <xsl:sequence select="analyze-string($ref,'([$]?)([A-Z]+)([$]?)([0-9]+)')"/> + </xsl:function> + <xsl:function name="e:cr" as="element(e:s)"> <!-- Parse a single cell reference into left and right halves, either e:a(bsolute) or e:r(elocatable) --> <xsl:param name="ref" as="xs:string" required="yes"/> <xsl:param name="row" as="xs:integer" required="yes"/> <xsl:param name="col" as="xs:integer" required="yes"/> - <xsl:variable name="cr" select="analyze-string($ref,'([$]?)([A-Z]+)([$]?)([0-9]+)')"/> + <xsl:variable name="cr" select="e:pr($ref)"/> <xsl:variable name="c" select="if ($cr//xpf:group[@nr=1][text()]) then 'a' else 'r'"/> <xsl:variable name="cv" select="e:a2n($cr//xpf:group[@nr=2])"/> <xsl:variable name="r" select="if ($cr//xpf:group[@nr=3][text()]) then 'a' else 'r'"/>
--- a/merge.xsl Tue May 09 23:08:18 2017 +0100 +++ b/merge.xsl Wed May 10 16:52:04 2017 +0100 @@ -18,7 +18,7 @@ <xsl:key name="ref" match="e:i" use="@r"/> <xsl:key name="nf" match="e:nf" use="text()"/> - <xsl:template match="/"><a><xsl:copy-of select="$nfs"/>|<xsl:value-of select="count($refs/e:i)"/>|<xsl:value-of select="count($nfs/e:nf)"/>|<xsl:value-of select="count(key('nf','SUM(ª2ª7:ª3ª7)',$nfs))"/>|<xsl:value-of select="count($nfs/e:nf[.='SUM(ª2ª7:ª3ª7)'])"/> + <xsl:template match="/xxx"><a><xsl:copy-of select="$nfs"/>|<xsl:value-of select="count($refs/e:i)"/>|<xsl:value-of select="count($nfs/e:nf)"/>|<xsl:value-of select="count(key('nf','SUM(ª2ª7:ª3ª7)',$nfs))"/>|<xsl:value-of select="count($nfs/e:nf[.='SUM(ª2ª7:ª3ª7)'])"/> <xsl:apply-templates/></a> </xsl:template> @@ -29,7 +29,6 @@ <c> <xsl:apply-templates select="@*"/> <xsl:if test="e:f"> - <xsl:message><xsl:value-of select="e:f"/></xsl:message> <xsl:attribute name="fi"><xsl:value-of select="key('nf',e:nf/text(),$nfs)/@i"/></xsl:attribute> </xsl:if> <xsl:if test="$reffed"><xsl:copy-of select="$reffed"/></xsl:if>
--- a/notes.txt Tue May 09 23:08:18 2017 +0100 +++ b/notes.txt Wed May 10 16:52:04 2017 +0100 @@ -189,6 +189,11 @@ abs ::= '\xAA' xs:positiveInteger rel ::= '\xAE' ( ( '-' xs:positiveInteger ) | xs:nonNegativeInteger ) ----------- +Would <c c=COL [fi= [si=]]> be sufficient? + fi an index into _all_ functions, si original index into explicitly + shared functions + Brute force for now -- rect sees shared table, computes CRNF +----------- Picking colours to label regions, e.g. with similar formulae: http://stackoverflow.com/questions/470690/how-to-automatically-generate-n-distinct-colors Start with just top-n, limited to 22 from Kelly
--- a/rect.xsl Tue May 09 23:08:18 2017 +0100 +++ b/rect.xsl Wed May 10 16:52:04 2017 +0100 @@ -7,7 +7,35 @@ <xsl:include href="n2a.xsl"/> <xsl:include href="tokenise.xsl"/> + <xsl:variable name="shared"> + <xsl:apply-templates select="collection()[2]/*"/> + </xsl:variable> + + <xsl:key name="shared" match="e:master" use="@si"/> + <xsl:variable name="dim" select="//s:dimension/@ref"/> + + <xsl:function name="e:analyse" as="element(*)*"> + <xsl:param name="formula" as="xs:string"/> + <xsl:param name="row" as="xs:integer"/> + <xsl:param name="col" as="xs:integer"/> + <xsl:variable name="toks" select="e:tokenise($formula,$row,$col)"/> + <xsl:sequence> + <f> + <xsl:copy-of select="$toks"/> + </f> + <nf><xsl:copy-of select="e:fnf($toks)"/></nf> + </xsl:sequence> + </xsl:function> + + <xsl:template match="e:master"> + <xsl:variable name="rp" select="e:pr(@r)"/> + <xsl:copy> + <xsl:copy-of select="@si"/> + <xsl:sequence select="e:analyse(text(),xs:integer($rp//xpf:group[@nr=4]), + e:a2n($rp//xpf:group[@nr=2]))"/> + </xsl:copy> + </xsl:template> <xsl:template match="/"> <xsl:apply-templates select="//s:sheetData"/> @@ -34,15 +62,16 @@ <xsl:if test="$c/*"> <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"> - <xsl:variable name="toks" select="e:tokenise($c/s:f,$row,$col)"/> - <f> - <xsl:copy-of select="$toks"/> - </f> - <nf> - <xsl:copy-of select="e:fnf($toks)"/> - </nf> - </xsl:if> + <xsl:variable name="si" select="$c/s:f/@si"/> + <xsl:copy-of select="$si"/> + <xsl:choose> + <xsl:when test="$c/s:f/text()"> + <xsl:sequence select="e:analyse($c/s:f/text(),$row,$col)"/> + </xsl:when> + <xsl:when test="$c/s:f/@si"> + <xsl:copy-of select="key('shared',$si,$shared)/*"/> + </xsl:when> + </xsl:choose> <xsl:value-of select="substring($c/@e:type,1,1)"/> </xsl:if> </c>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/shared.xsl Wed May 10 16:52:04 2017 +0100 @@ -0,0 +1,21 @@ +<?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 e xf" xmlns="http://markup.co.uk/excel" xmlns:xf="http://www.w3.org/2005/xpath-functions"> + + <xsl:template match="/"> + <masters><xsl:apply-templates select="/s:worksheet/s:sheetData"/></masters> + </xsl:template> + + <xsl:template match="s:sheetData"> + <xsl:variable select="s:row/s:c/s:f[@si]" name="sfs"/> + <xsl:variable name="indices" select="distinct-values(for $sf in $sfs/@si return string($sf))"> + <!-- s:f/@si values --> + </xsl:variable> + + <xsl:for-each select="$indices"> + <xsl:variable name="i" select="."/> + <xsl:variable name="sf" select="($sfs[@si=$i])[1]"/> + <master si="{$i}" r="{$sf/../@r}"><xsl:value-of select="$sf"/></master> + </xsl:for-each> + </xsl:template> +</xsl:stylesheet>
--- a/visualise.xpl Tue May 09 23:08:18 2017 +0100 +++ b/visualise.xpl Wed May 10 16:52:04 2017 +0100 @@ -21,6 +21,12 @@ </p:documentation> </p:option> + <p:option name="raw"> + <p:documentation xmlns="http://www.w3.org/1999/xhtml"> + <div>If supplied, then use as output file for rect step</div> + </p:documentation> + </p:option> + <p:variable name="base" select="base-uri()"> <p:pipe step="vis" port="source"/> </p:variable> @@ -77,13 +83,40 @@ <p:xslt name="rect"> <p:input port="source"> <p:pipe step="format" port="result"/> + <p:pipe step="shared" 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:xslt> + + <p:choose> + <p:when test="p:value-available('raw')"> + <cx:message> + <p:with-option name="message" select="concat($root,'worksheets/',$raw)"/> + </cx:message> + <p:store name="dump"> + <p:input port="source"> + <p:pipe step="rect" port="result"/> + </p:input> + <p:with-option name="href" select="concat($root,'worksheets/',$raw)"/> + </p:store> + <p:sink> + <p:input port="source"> + <p:pipe step="dump" port="result"/> + </p:input> + </p:sink> + </p:when> + <p:otherwise> + <p:sink> + <p:input port="source"> + <p:pipe step="rect" port="result"/> + </p:input> + </p:sink> + </p:otherwise> + </p:choose> <p:load name="ssr"> <p:with-option name="href" select="concat($elabDir,'/refs.xsl')"/>