comparison rect.xsl @ 26:d2ca3ea1f5ae

plumb in and use inverted ref table (via key)
author Henry S. Thompson <ht@markup.co.uk>
date Fri, 07 Apr 2017 18:42:47 +0100
parents 87e0d620deea
children 8309dcfce613
comparison
equal deleted inserted replaced
25:a5125a2e77ea 26:d2ca3ea1f5ae
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 xpf" xmlns="http://markup.co.uk/excel" xmlns:xpf="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 xpf" xmlns="http://markup.co.uk/excel" xmlns:xpf="http://www.w3.org/2005/xpath-functions">
4 <xsl:strip-space elements="s:sheetData"/> 4 <xsl:strip-space elements="s:sheetData"/>
5 5
6 <xsl:variable name="refs" select="collection()[2]/*"/> 6 <xsl:variable name="refs" select="collection()[2]/*"/>
7 7
8 <xsl:key name="ref" match="e:ref" use="e:s"/> 8 <xsl:key name="ref" match="e:i" use="@r"/>
9 9
10 <xsl:function name="e:a2n" as="xs:integer"> 10 <xsl:function name="e:a2n" as="xs:integer">
11 <!-- Convert an alphabetic excel column 'index' into a number, 11 <!-- Convert an alphabetic excel column 'index' into a number,
12 a sort of base 26 + 1, since 'A' is 1 and 'AA' is 27 --> 12 a sort of base 26 + 1, since 'A' is 1 and 'AA' is 27 -->
13 <xsl:param name="aa" as="xs:string"/> 13 <xsl:param name="aa" as="xs:string"/>
37 <xsl:template match="/"> 37 <xsl:template match="/">
38 <xsl:apply-templates select="//s:sheetData"/> 38 <xsl:apply-templates select="//s:sheetData"/>
39 </xsl:template> 39 </xsl:template>
40 40
41 <xsl:template match="s:sheetData"> 41 <xsl:template match="s:sheetData">
42 <xsl:message><xsl:value-of select="count($refs/*)"/></xsl:message>
42 <xsl:if test="s:row"> 43 <xsl:if test="s:row">
43 <xsl:variable name="dims" select="analyze-string($dim,'([A-Z]+)([0-9]+):([A-Z]+)([0-9]+)')"/> 44 <xsl:variable name="dims" select="analyze-string($dim,'([A-Z]+)([0-9]+):([A-Z]+)([0-9]+)')"/>
44 <xsl:variable name="height" select="1+xs:integer($dims//xpf:group[@nr='4'])-xs:integer($dims//xpf:group[@nr='2'])"/> 45 <xsl:variable name="height" select="1+xs:integer($dims//xpf:group[@nr='4'])-xs:integer($dims//xpf:group[@nr='2'])"/>
45 <xsl:variable name="width" select="1+e:a2n($dims//xpf:group[@nr='3'])-e:a2n($dims//xpf:group[@nr='1'])"/> 46 <xsl:variable name="width" select="1+e:a2n($dims//xpf:group[@nr='3'])-e:a2n($dims//xpf:group[@nr='1'])"/>
46 <!-- Brute force! --> 47 <!-- Brute force! -->
57 <xsl:variable name="c" select="$cells[@r=$r]"/> 58 <xsl:variable name="c" select="$cells[@r=$r]"/>
58 <xsl:variable name="reffed" select="key('ref',$r,$refs)"/> 59 <xsl:variable name="reffed" select="key('ref',$r,$refs)"/>
59 <c c="{$col}"> 60 <c c="{$col}">
60 <xsl:if test="$c/s:f"><xsl:attribute name="f">1</xsl:attribute></xsl:if> 61 <xsl:if test="$c/s:f"><xsl:attribute name="f">1</xsl:attribute></xsl:if>
61 <xsl:if test="$c/*"><t><xsl:value-of select="substring($c/@e:type,1,1)"/></t></xsl:if> 62 <xsl:if test="$c/*"><t><xsl:value-of select="substring($c/@e:type,1,1)"/></t></xsl:if>
62 <xsl:if test="$reffed"><xsl:for-each select="$reffed/@c"><r><xsl:value-of select="."/></r></xsl:for-each></xsl:if> 63 <xsl:if test="$reffed"><xsl:copy-of select="$reffed/e:r"/></xsl:if>
63 </c> 64 </c>
64 </xsl:for-each></xsl:if> 65 </xsl:for-each></xsl:if>
65 </r> 66 </r>
66 <xsl:text>&#10;</xsl:text></xsl:for-each> 67 <xsl:text>&#10;</xsl:text></xsl:for-each>
67 </a> 68 </a>