Mercurial > hg > ooxml
diff a2n.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 | 5d9806f90896 |
line wrap: on
line diff
--- a/a2n.xsl Thu Apr 13 23:09:58 2017 +0100 +++ b/a2n.xsl Tue Apr 25 12:24:31 2017 +0100 @@ -1,13 +1,42 @@ <?xml version='1.0'?> <!DOCTYPE xsl:stylesheet SYSTEM "file:///C:/C64/home/ht/lib/xml/xsl.dtd" > -<xsl:stylesheet xmlns:e="http://markup.co.uk/excel" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="3.0"> - <xsl:function name="e:a2n" as="xs:integer"> +<xsl:stylesheet xmlns:e="http://markup.co.uk/excel" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="3.0" xmlns:xpf="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="e xpf xs" xmlns="http://markup.co.uk/excel"> + + <xsl:function name="e:a2n" as="xs:integer"> <!-- Convert an alphabetic excel column 'index' into a number, a sort of base 26 + 1, since 'A' is 1 and 'AA' is 27 --> - <xsl:param name="aa" as="xs:string"/> + <xsl:param name="aa" as="xs:string" required="yes"/> + <xsl:variable name="codeBase" select="string-to-codepoints('A')-1"/> <xsl:value-of select="let $l := string-length($aa), $lv := string-to-codepoints(substring($aa,$l))-$codeBase return if ($l=1) then $lv else $lv+(26*e:a2n(substring($aa,1,$l - 1)))"/> </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="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'"/> + <xsl:variable name="rv" select="xs:integer($cr//xpf:group[@nr=4])"/> + <s r="{$ref}"> + <xsl:element name="{$c}" namespace="http://markup.co.uk/excel"> + <xsl:if test="$c='r'"> + <xsl:attribute name="d"><xsl:value-of select="$cv - $col"/></xsl:attribute> + </xsl:if> + <xsl:value-of select="$cv"/> + </xsl:element> + <xsl:element name="{$r}" namespace="http://markup.co.uk/excel"> + <xsl:if test="$r='r'"> + <xsl:attribute name="d"><xsl:value-of select="$rv - $row"/></xsl:attribute> + </xsl:if> + <xsl:value-of select="$rv"/> + </xsl:element> + </s> + </xsl:function> </xsl:stylesheet>